重置 MySQL 的 root 用户密码
情况:Linux中安装了MySQL,过几天忘记了密码,且没有任何远程连接工具连接了它。
注:如果有远程工具(比如Navicat)连接了数据库,此时可以使用其他方式,不需要采用下面的方法。
首先,你必须要有操作系统的root权限了。
执行 /etc/init.d/mysqld stop。
[root@ecs-e25c-0001 local]# mysqld_safe --skip-grant-tables &
[root@ecs-e25c-0001 local]# mysql
mysql> use mysql
mysql> UPDATE user SET password=password("新密码") WHERE user='root' ;
mysql> flush privileges;
mysql> exit;
多谢 @敲代码的混子
如果mysql提示没有password字段,则第四步可以使用:
mysql> update mysql.user set authentication_string=password('你的密码') where user='root';