mysql数据库修改密码

1.修改 /etc/my.cnf配置文件,在 [mysqld]下添加一行:

skip-grant-tables=1

      这一行配置让 mysqld 启动时不对密码进行验证

2.重启 mysqld 服务:

systemctl restart mysqld

3.使用 root 用户登录到 mysql:

mysql -u root

4.切换到mysql数据库(use mysql),更新 user 表:

use mysql

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

        在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string

5、退出 mysql,编辑 /etc/my.cnf 配置文件,删除 skip-grant-tables=1 这一行

       vim /etc/my.cnf

6、 重启mysqld服务,再用新密码登录即可

systemctl restart mysqld

原文地址:https://www.cnblogs.com/recall-lonely/p/10754897.html