【MySQL解惑笔记】忘记MySQL数据库密码
生活随笔
收集整理的這篇文章主要介紹了
【MySQL解惑笔记】忘记MySQL数据库密码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
破解MySQL密碼
一、MySQL5.7.5之前
只要有系統root密碼就可以破解: [root@host-131 ~]# vim /etc/my.cnf //在配置文件中加入如下內容 [mysqld] skip-grant-tables[root@host-131 ~]# systemctl restart mysqld //重啟MySQL服務 [root@host-131 ~]# mysql mysql> update mysql.user set password=password("Yanglt456.") where user="root" and host="localhost"; //設置密碼 mysql> flush privileges; //刷新 mysql> \q[root@host-131 ~]# vim /etc/my.cnf //注釋掉下邊內容,或者直接刪除 [mysqld] #skip-grant-table [root@host-131 ~]#systemctl restart mysqld //重啟服務
一、MySQL5.7.6之后
[root@host-131 ~]# vim /etc/my.cnf [mysqld] skip-grant-tables mysql> select user,host,authentication_string from mysql.user; +---------------+-----------+-------------------------------------------+ | user | host | authentication_string | +---------------+-----------+-------------------------------------------+ | root | localhost | *8F59EEA84BC6AA6A57ECD4C0377518281DADC1BA | | mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | +---------------+-----------+-------------------------------------------+ 3 rows in set (0.01 sec)mysql> desc mysql.user; +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Host | char(60) | NO | PRI | | | | User | char(32) | NO | PRI | | | | authentication_string | text | YES | | NULL | | | password_expired | enum('N','Y') | NO | | N | | | password_last_changed | timestamp | YES | | NULL | | | password_lifetime | smallint(5) unsigned | YES | | NULL | | | account_locked | enum('N','Y') | NO | | N | | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ 45 rows in set (0.01 sec)mysql> update mysql.user set authentication_string=password("Yanglt456.") where user="root"; mysql> flush privileges; mysql> \q[root@host-131 ~]# vim /etc/my.cnf [mysqld] #skip-grant-tables //注釋掉 [root@host-131 ~]# systemctl restart mysqld //重啟mysql服務 [root@host-131 ~]# mysql -p"Yanglt456." //密碼已改變
?
轉載于:https://www.cnblogs.com/yangleitao/p/9109607.html
總結
以上是生活随笔為你收集整理的【MySQL解惑笔记】忘记MySQL数据库密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]mysql 数据类型
- 下一篇: 《长相思·九月西风兴》是哪个时期的作品?