1.强制关闭mysql
# pkill mysql
2.向配置文件添加
[mysqld]
skip-grant-tables
3.重启mysql
-
# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
-
[1] 29335
-
[root@mysql5 logs]# 180310 21:00:11 mysqld_safe Logging to '/home/mysql3306/logs/mysql-error.log'.
-
180310 21:00:11 mysqld_safe Starting mysqld daemon with databases from /home/mysql3306/mysql3306
4.无密码登录
# /usr/local/mysql/bin/mysql -S /tmp/mysql.sock
5.重置root密码
-
mysql> update mysql.user set password=password('root') where user='root';
-
Query OK, 2 rows affected (0.03 sec)
-
Rows matched: 4 Changed: 2 Warnings: 0
-
-
mysql> flush privileges;
-
Query OK, 0 rows affected (0.02 sec)
6.重启mysql
# pkill mysql
将
skip-grant-tables从配置文件注销掉
# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
7.验证
# /usr/local/mysql/bin/mysql -S /tmp/mysql.sock -uroot -p