- 找到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
- 关闭mysql服务
service mysql stop
- 以--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 &
- 用空密码的root连接mysql
mysql -uroot
- 修改root密码
update user set password=password("xxx") where user=‘root‘ and host = ‘localhost‘;
- 刷新权限表
flush privileges;
- 手动杀掉mysql进程
ps aux | grep mysqld
kill -9 xxx
- 正常启动mysql
serice mysql start
MySQL 忘记root密码