[root@db01 ~]# systemctl stop firewalld
[root@db01 ~]# /etc/init.d/mysqld stop
[root@db03 ~]# ps -ef |grep mysqld
root 21557 21480 0 13:25 pts/1 00:00:00 grep --color=auto mysqld
[root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &
#跳过授权表,启动mysql #跳过授权表后,就可以直接登录mysql,不需要密码
注:一个非常有用的mysql启动参数—— --skip-grant-tables。顾名思义,就是在启动
mysql时不启动grant-tables,授权表 --skip-networking是不让别的用户远程登陆
[root@db03 ~]# mysql
mysql> update mysql.user set password=PASSWORD(‘123‘) where user=‘root‘ and host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
#使用update修改roo密码(直接修改MySQL库里的user表里的password这个字段)
mysql> flush privileges; #刷新系统授权表
Query OK, 0 rows affected (0.00 sec)
mysql> exit或 quit或 \q #停止mysqld_safe进程
[root@db03 ~]# mysql -uroot -p123 #再次登录
6)和7)不知道这两条命令干嘛 用的
6)mysqladmin -uroot -p123 shutdown
#使用系统命令启动mysql
7)systemctl start mysql
6.1 mysql不用密码登陆
[root@db04 ~]# vim /etc/my.cnf
这样下次再登陆的时候就不用密码登陆啦!!!!!