已解决
解决方案如下:
vi /etc/my.cnf
mysqld下加
[backcolor=rgb(245, 245, 245)]skip-grant-tables[/backcolor]
[mysqld]
skip-grant-tables
[backcolor=rgb(253, 253, 253)]:wq! #保存退出[/backcolor][backcolor=rgb(253, 253, 253)]然后重启Mysql服务器[/backcolor]
service mysqld restart
进入Mysql控制台,这时候密码空
mysql -uroot -p
修改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;
取消/etc/my.cnf中的skip-grant-tables
vi /etc/my.cnf
[backcolor=rgb(253, 253, 253)]找到[mysqld],删除skip-grant-tables这一行[/backcolor]
[backcolor=rgb(253, 253, 253)]:wq! #保存退出[/backcolor]
[backcolor=rgb(253, 253, 253)]重启服务器[/backcolor]
service mysqld restart
搞定