MySQL数据库root密码丢失破解方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MySQL数据库root密码丢失破解方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4921字,纯文字阅读大概需要8分钟。
内容图文
![MySQL数据库root密码丢失破解方法](/upload/InfoBanner/zyjiaocheng/499/9952d92d9212440ea9823f9f541a5f53.jpg)
第1章 单实例破解方法
1.1 停止mysql服务
[root@mysql01 ~]# /etc/init.d/mysqld stop Shutting down MySQL. SUCCESS!
1.2 重新启动mysql启动
直接使用mysqld_safe命令启动,并添加参数--skip-grant-tables,跳过权限认证表
[root@mysql01 ~]# mysqld_safe --skip-grant-tables & [1] 5985 [root@mysql01 ~]# 180125 05:17:49 mysqld_safe Logging to '/opt/mysql/data/mysql01.err'. 180125 05:17:49 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data
1.3 直接无密码登录mysql
步骤2启动成功之后,则不需要密码就能够登录数据库:
[root@mysql01 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.55 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. mysql>
1.4 修改root密码
使用mysql命令中的UPDATE修改密码
mysql> update mysql.user SET password=PASSWORD("123456") WHERE user='root' and host='localhost' Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
update:修改密码命令
mysql.user:存放用户信息的数据库和表格
SET:设置密码参数
password=PASSWORD("123456"):设置新的密码,其中PASSWORD的目的是给“123456”加密,必须添加该参数
WHERE user='root' and host='localhost':定位需要修改密码的用户
1.5 刷新用户权限:
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
1.6 退出并重启数据库
kill PID [root@mysql01 ~]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS!
修改完成!
[root@mysql01 ~]# mysql -uroot -p123456
第2章 多实例破解方法
多实例破解方式和但实例类似,只是要接的参数更多些。
2.1 停止MySQL服务
首先通过ps -ef查找到mysqld服务对应的进程号,然后通过kill命令将进程杀掉。
[root@localhost support-files]# ps -ef |grep 3308 | grep -v grep root 59695 1 0 04:15 pts/1 00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --defaults-file=/data/3308/my.cnf mysql 60419 59695 0 04:15 pts/1 00:00:07 /opt/mysql-5.5.32/bin/mysqld --defaults-file=/data/3308/my.cnf --basedir=/opt/mysql --datadir=/data/3308/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/data/3308/mysql_3308.err --open-files-limit=8192 --pid-file=/data/3308/mysqld.pid --socket=/data/3308/mysql.sock --port=3308 [root@localhost support-files]# kill 60419
注:此处不能使用kill -9参数,否则会造成严重的后果
2.2 使用mysqld_safe启动
[root@localhost 3308]# mysqld_safe --defaults-file=/data/3308/my.cnf --skil-grant-table & [1] 61039 [root@localhost 3308]# 180127 07:11:02 mysqld_safe Logging to '/var/log/mysqld.log'. 180127 07:11:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 180127 07:11:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended [1]+ Done mysqld_safe --default-file=/data/3308/my.cnf --skil-grant-tables
注:参数--skil-grant-tables需添加在命令末尾。
2.3 无密码登录数据库
多实例登录mysql数据库需要指定sock文件:
[root@localhost 3308]# mysql -uroot -p -S /data/3308/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.32 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>
2.4 重新设置密码
mysql> update mysql.user SET password=PASSWORD("123456") where user='root' and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>
2.5 刷新用户权限
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
2.6 退出并重启数据库
[root@localhost 3308]# kill 61955 [root@localhost 3308]# 180127 07:19:08 mysqld_safe mysqld from pid file /data/3308/mysqld.pid ended [1]+ Done mysqld_safe --defaults-file=/data/3308/my.cnf --skip-grant-table [root@localhost 3308]# /data/3308/mysql start Starting MySQL......
2.7 重新登录
[root@localhost 3308]# mysql -uroot -p123456 -S /data/3308/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.32 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>
完成!!
MySQL数据库root密码丢失破解方法
标签:指定 hang 修改密码命令 密码 open str 数据库 重启 state
本文系统来源:http://blog.51cto.com/13178102/2066012
内容总结
以上是互联网集市为您收集整理的MySQL数据库root密码丢失破解方法全部内容,希望文章能够帮你解决MySQL数据库root密码丢失破解方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。