mysql 常用操作

启动服务 

[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb

初始化

mysql_secure_installation

防火墙

firewall-cmd –permanent –add-service=mysql
firewall-cmd –reload

忘记密码

  1. 修改MySQL的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行
    skip-grant-tables 
  2. 保存配置文件后,重启MySQL服务 systemctl restart mysqld 
  3. 再次进入MySQL命令行 mysql -u root -p, 输入密码时直接回车,就会进入MySQL数据库了,这个时候按照常规流程修改root密码即可。依次输入:
    > use mysql;
  4. 更改数据库
    >UPDATE user SET PASSORD =password(“自己重新设置的密码写此处”) WHERE USER= ‘root’;  重设密码
  5. 如果是 centos 7以上的;可能会失败;修改密码操作改为:
    update mysql.user set authentication_string=password('自己重新设置的密码写此处') where user='root' ;
  6. >flush privileges;  刷新MySQL的系统权限相关表,以防止更改后拒绝访问;或或者重启MySQL服务器
  7. 密码修改完毕后,再按照步骤1中的流程,删掉配置文件中的那行,并且重启MySQL服务,新密码就生效了。

备份

 1、备份一个或多个表

    mysqldump [options] db_name [table_name……]

  2、备份一个或多个库

     mysqldump [options] –databases dbname……

 3、备份所有数据库

   mysqldump [options] –all-databases

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.