当前位置:Gxlcms > 数据库问题 > MySQL系列-修改root密码

MySQL系列-修改root密码

时间:2021-07-01 10:21:17 帮助过:3人阅读

1.关闭mysql服务

systemctl stop mysqld

netstat -tunlp|grep mysqld

 

2.进入配置文件添加一条命令

[mysqld]

skip-grant-tables    #以安全模式启动

 

3.重新启动服务

systemctl start mysqld

 

4.无密码模式登陆

mysql -uroot

 

5. 5.7版本以后password字段没有,更改为authentication_string

 

show databases;
use mysql;
show tables;
desc user;
update mysql.user set authentication_string=password(‘xxx‘) where user=‘root‘ ;
flush privileges;

 

 

6.修改完毕后将配置文件中添加的语句注释掉,并重启服务

vim /etc/my.cnf
#skip-grant-tables systemctl restart mysqld

 

7.新密码重新登陆后出现问题

show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#意思是必须使用alter user命令重新设置密码

mysql> alter user root@localhost identified by XXXXXX;

flush privileges;

 

 

 

MySQL系列-修改root密码

标签:str   登陆   system   linu   his   linux   文件   xxx   语句   

人气教程排行