1、先找到my.cnf文件
find / -name my.cnf
2、编辑文件
vi /etc/my.cnf
找到[mysqld],在下面添加一行skip-grant-tables
[mysqld]
skip-grant-tables
3、保存退出,并重启mysql服务
:wq!
service mysqld restart
4、进入MySQL控制台
mysql -uroot -p
#直接按回车,这时不需要输入root密码。
5、修改root密码
update mysql.user set password=password('123456') where User="root" and Host="localhost"; flush privileges; #刷新系统授权表 grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;
6、取消/etc/my.cnf中的skip-grant-tables
vi /etc/my.cnf
编辑文件,找到[mysqld],删除skip-grant-tables这一行
:wq! #保存退出
7、重启mysql
service mysqld restart
#重启mysql,这个时候mysql的root密码已经修改为123456
8、进入mysql控制台
mysql -uroot -p
#进入mysql控制台
123456 #输入密码
浙公网安备 33010602011771号