[MYSQL]Mysql 数据库丢失Root密码恢复

单实例:
killall mysqld
mysqld_safe –skip-grant-tables &
mysql -u root -p

多实例:
killall mysqld
mysqld_safe –defaults-file=/data/3306/my.cnf –skip-grant-table &
mysql -u root -p -S /data/3306/mysql.sock

登陆后修改密码:
mysql> UPDATE mysql.user SET password=PASSWORD(“kqzjhack″) WHERE user=’root’;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

重起mysql登陆测试(多实例修改密码后测试):
/data/3306/mysql restart

[root@ryan01 3306]# mysql -u root -p’hyran123′ -S /data/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>

可以看到已经登陆进来

文章目录
,