mysql管理员帐号密码_忘记mysql root管理员帐号密码处理方法

概述

丢失root密码,意味着不能以超级管理员帐号登录数据库,进行维护工作。需要找回root密码。

处理方法

杀掉mysql进程,然后添加一个参数–skip-grant-tables跳过权限表,启动mysql实例,然后以无密码方式登录数据库,修改root用户密码,再关闭mysql实例(关闭或者kill mysql进程),最后正常启动mysql实例,就可以使用root用户登录数据库了。

关键操作代码

mysql -uroot -p

ps -ef|grep mysql

kill -9 mysql进程号

mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &

mysql

use mysql;

update user set authentication_string=password(‘oracle123’) where user=‘root’;

flush privileges;

mysqladmin -p shutdown

mysqld_safe --defaults-file=/etc/my.cnf &

mysql -uroot -p

操作演示日志

[root@source ~]# mysql -uroot -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ==故意输错密码,模拟root密码丢失==

[root@source ~]#

[root@source ~]# ps -ef|grep mysql

root 6733 6191 0 10:28 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf

mysql 7029 6733 2 11:10 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin

--user=mysql --log-error=source.err --pid-file=source.pid --port=3306

root 7063 6191 0 11:10 pts/0 00:00:00 grep mysql

[root@source ~]#

[root@source ~]# kill -9 7029 6733

[root@source ~]#

[1]+ Killed mysqld_safe --defaults-file=/etc/my.cnf

[root@source ~]#

[root@source ~]# ps -ef|grep mysql

root 7066 6191 0 11:10 pts/0 00:00:00 grep mysql

[root@source ~]#

[root@source ~]#

[root@source ~]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &

[1] 7286

[root@source ~]# 2020-02-16T03:11:41.998645Z mysqld_safe Logging to '/data/mysql/source.err'.

2020-02-16T03:11:42.020962Z mysqld_safe Starting mysqld daemon with databases from /data/mysql

[root@source ~]#

[root@source ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

root@db 11:11: [(none)]>

root@db 11:11: [(none)]>

root@db 11:12: [(none)]>

root@db 11:12: [(none)]> use mysql;

Database changed

root@db 11:12: [mysql]>

root@db 11:12: [mysql]> update user set authentication_string=password('oracle123') where user='root'; ==修改密码==

Query OK, 1 row affected, 1 warning (0.01 sec)

Rows matched: 2 Changed: 1 Warnings: 1

root@db 11:13: [mysql]>

root@db 11:13: [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

root@db 11:13: [mysql]>

root@db 11:14: [mysql]> exit

Bye

[root@source ~]#

[root@source ~]# mysqladmin -p shutdown

Enter password:

[root@source ~]#

[root@source ~]# 2020-02-16T03:15:27.217666Z mysqld_safe mysqld from pid file /data/mysql/source.pid ended

[1]+ Done mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables

[root@source ~]#

[root@source ~]# ps -ef|grep mysql

root 7502 6191 0 11:15 pts/0 00:00:00 grep mysql

[root@source ~]#

[root@source ~]# mysqld_safe --defaults-file=/etc/my.cnf &

[1] 7503

[root@source ~]# 2020-02-16T03:15:57.181920Z mysqld_safe Logging to '/data/mysql/source.err'.

2020-02-16T03:15:57.217614Z mysqld_safe Starting mysqld daemon with databases from /data/mysql

[root@source ~]#

[root@source ~]# mysql -uroot -p

Enter password: ==root密码找回后,正常登录==

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

root@db 11:16: [(none)]>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值