一、更改my.cnf配置文件
1.用编辑配置文件/etc/my.cnf
2.在[mysqld]下添加skip-grant-tables,然后保存并退出
3.重启mysql服务:
service mysqld restart
二、更改root用户名
1.重启以后,执行mysql命令进入mysql命令行
2.修改root用户密码
MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root';
MySQL> flush privileges;
MySQL> exit
3.把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql
即:service mysqld restart
好了,可以用root新的密码登录了!
8.0
3.输入:mysql -u root -p,回车进入mysql(此时不需要密码即可直接进入)
4.输入:use mysql;
5.输入:update user set authentication_string=‘’ where user=‘root’;,将authentication_string 置空;
6.输入:alter user ‘root’@‘localhost’ identified by ‘newpassword’;,newpassword为要修改的新密码;
此时提示错误:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement输入:
FLUSH PRIVILEGES;
再重新alter user ‘root’@‘localhost’ identified by ‘newpassword’;
此时错误提示为:ERROR 1524 (HY000): Plugin ‘auth_socket’ is not loaded,
输入select user,plugin from mysql.user;来查看plugin
这里输入update user set plugin=‘mysql_native_password’ where user=‘root’;将plugin改为以前版本的密码认证方式然后输入:
FLUSH PRIVILEGES;