MySQL 忘记root密码

  1. 找到mysqld_safe的启动命令,记录下来
ps aux | grep mysqld_safe

// /home/soft/mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysqld_safe --datadir=/home/soft/mysql-5.7.25-linux-glibc2.12-x86_64/data --pid-file=/home/soft/mysql-5.7.25-linux-glibc2.12-x86_64/data/localhost.localdomain.pid
  1. 关闭mysql服务
service mysql stop
  1. 以--skip-grant-tables命令重新启动mysql
./bin/mysqld_safe --skip-grabt-tables --datadir=/home/soft/mysql-5.7.25-linux-glibc2.12-x86_64/data --pid-file=/home/soft/mysql-5.7.25-linux-glibc2.12-x86_64/data/localhost.localdomain.pid &
  1. 用空密码的root连接mysql
mysql -uroot
  1. 修改root密码
update user set password=password("xxx") where user=‘root‘ and host = ‘localhost‘;
  1. 刷新权限表
flush privileges;
  1. 手动杀掉mysql进程
ps aux | grep mysqld

kill -9 xxx 
  1. 正常启动mysql
serice mysql start

MySQL 忘记root密码

上一篇:清理mysql特定数据


下一篇:sql查询