mysql root密码忘记
young / / / 阅读量

修改MySQL的配置文件(默认为/etc/my.cnf),

在[mysqld]下添加一行

skip-grant-tables

保存配置文件后,重启MySQL服务

[root@localhost~]#  service mysqld restart

再次进入MySQL命令行

[root@localhost~]#  mysql -uroot -p

输入密码时直接回车,就会进入MySQL数据库了.
更改root密码

update mysql.user set password=password('123456') where user='root' and host='localhost';

5.7修改密码

update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';

特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了

再次查看账户信息,select user,host,password from user; 可以看到密码已被修改。
然后退出数据库 就能用新密码进行登录了
记得要把 数据库配置文件 /etc/my.cnf 中的skip-grant-tables删掉 ,不然一直都会不用密码就能登录mysql

支付宝捐赠
请使用支付宝扫一扫进行捐赠
微信捐赠
请使用微信扫一扫进行赞赏
有 0 篇文章