Linux 下修改MySQL密码

1. 管理员登录Linux

2. 配置文件中增加跳过权限

2.1 编辑配置文件:

vim /etc/my.cnf

2.2 在文件最后一行输入:

skip-grant-tables

2.3 保存

:wq

2.4 重启MySQL服务

systemctl restart mysqld

3. root账户登录MySQL

mysql -uroot -p

提示输入密码,直接回车。

4. 修改密码

4.1 指定操作数据库

use mysql

4.2 更新密码为123456

MySQL 5.7 之前:

update user set password=password('123456') where user='root';

MySQL 5.7 之后:

update user set authentication_string=password('123456') where user='root';

4.3 刷新权限

flush privileges;

4.4 退出MySQL

exit;

5. 还原配置文件

5.1 编辑配置文件:

vim /etc/my.cnf

5.2 注释之前的一行:

# skip-grant-tables

5.3 保存

:wq

5.4 重启MySQL服务

systemctl restart mysqld
发布了420 篇原创文章 · 获赞 143 · 访问量 89万+

猜你喜欢

转载自blog.csdn.net/jeikerxiao/article/details/104832992