本文标题:Linux中修改Mysql密码
原始链接:https://shuibo.cn/mysql-update-password.html
许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者
1.记得root密码的情况下
登录MySql
mysql -uroot -p
Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD("123456") where user='root';
mysql> flush privileges;
mysql> exit;
注意:
如果MySql版本5.7及以上的话修改语句为
mysql> update user set authentication_string=passworD("123456") where user='root';
2.忘记root密码的情况下
首先拿到操作系统的root权限,然后kill掉Mysql服务或者手动stop掉、例如手动
service mysql stop
然后执行
mysqld_safe --skip-grant-tables &
&,表示在后台运行,不再后台运行的话,就再打开一个终端吧。
接着登录MySQL修改密码
mysql> use mysql;
mysql> UPDATE user SET password=password("123456") WHERE user='root';
mysql> flush privileges;
mysql> exit;
注意:
如果MySql版本5.7及以上的话修改语句为
mysql> update user set authentication_string=passworD("123456") where user='root';