1、更改my.cnf配置文件
1.用編輯配置文件/etc/my.cnf

2.在[mysqld]下添加skip-grant-tables,而後保存並退出

3.重啓mysql服務:
service mysqld restart
2、更改root用戶名
1.重啓之後,執行mysql命令進入mysql命令行

2.修改root用戶密碼
MySQL> UPDATE mysql.user SET Password=PASSWORD('新密碼') where USER='root';
MySQL> flush privileges;mysql
MySQL> exitsql

3.把/etc/my.cnf中的skip-grant-tables註釋掉,而後重啓mysql,即:service mysqld restart
好了,能夠用root新的密碼登陸了spa
mysql -u root -p
