码迷,mamicode.com
首页 > 数据库 > 详细

MySQL root密码找回

时间:2016-02-16 23:23:41      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

以MySQL多实例为例,演示找回MySQL root的密码

1、关闭mysql服务

[root@mysql ~]# mysqladmin -uroot -poldboy123 -S /data/3306/mysql.sock shutdown  ==>通过mysqladmin shutdown优雅关闭mysql服务。
[root@mysql ~]# lsof -i:3306

2、使用--skip-grant-tables参数后台启动mysql,忽略授权验证直接登录

[root@mysql ~]# mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables &  ==>--skip-grant-tables这个参数一定要放在默认文件的后面,&表示后台启动。
[1] 63540
[root@mysql ~]# 160216 22:27:26 mysqld_safe Logging to ‘/data/3306/mysql_oldboy3306.err‘.
160216 22:27:26 mysqld_safe Starting mysqld daemon with databases from /data/3306/data
^C
[root@mysql ~]# lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  64277 mysql   12u  IPv4 127392      0t0  TCP *:mysql (LISTEN)

3、登录mysql,使用update语句修改MySQL root密码

[root@mysql ~]# mysql -S /data/3306/mysql.sock   ==>做了忽略授权认证,不用密码直接登录;
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> update mysql.user set password=PASSWORD("oldboy123") where user=‘root‘ and host=‘localhost‘; ==>使用update语句修改MySQL root密码。
Query OK, 0 rows affected (0.26 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> flush privileges;  ==>一定要刷新授权表。
Query OK, 0 rows affected (0.05 sec)

mysql> \q
Bye

4、使用修改后的root密码登录mysql

[root@mysql ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock  ==>使用root密码登录。
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.32-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> 

 

至此,找回并修改root密码成功。

 

MySQL root密码找回

标签:

原文地址:http://www.cnblogs.com/mrwang1101/p/5194002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!