天天看點

mysql忘記密碼後重置密碼的問題

   5.5版本

忘記原來的myql的root的密碼;首先,你必須要有作業系統的root權限了。

要是連系統的root權限都沒有的話,先考慮root系統再走下面的步驟。

先看程序

ps -aux|grep mysql

殺死程序。

下面的ID指對應的程序

kill -9 ID

停止服務。

是以一般是這樣

/etc/init.d/mysqld stop
# mysqld_safe --skip-grant-tables &&, /bin/systemctl stop  mysql.service (最近www.oneinstack.com方法安裝的,用這句)

表示在背景運作再打開一個終端。

這裡無需密碼就能進入了。

# mysql

打開mysql.

mysql> use mysql;

修改密碼:

mysql 5.6用這一句:

mysql> UPDATE user SET password=password("test123") WHERE user='root'; 

mysql 5.7用這一句:

mysql> update mysql.user set authentication_string=password('test123') where user='root' and Host = 'localhost';  

讓其生效。

mysql> flush privileges;

退出。

mysql> exit;                         

##本來mysql是不分大小寫的,但是這個是修改的mysql中的mysql資料庫的具體的值,要注意到。

[root@iZ626s67tu3Z init.d]# mysqld_safe --skip-grant-tables &

[1] 7221

[root@iZ626s67tu3Z init.d]# 2017-03-15T12:31:32.188353Z mysqld_safe Logging to '/data/mysql/mysql-error.log'.

2017-03-15T12:31:32.238110Z mysqld_safe Starting m

ysqld daemon with databases from /data/mysql

另外是打開3306端口:

iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

這一句我終于記住了!

還有開啟遠端通路:

mysql> use mysql;  

mysql> update user set host = '%' where user = 'root';  

mysql> select host, user from user;  

mysql> flush privileges;  

網上還有幾篇可參考一下:   

<a href="http://blog.csdn.net/wooshn/article/details/7786473" target="_blank">http://blog.csdn.net/wooshn/article/details/7786473</a>

<a href="http://blog.csdn.net/wooshn/article/details/7786473" target="_blank"></a>

<a href="http://blog.csdn.net/yageeart/article/details/7973381" target="_blank">http://blog.csdn.net/yageeart/article/details/7973381</a>

     本文轉自phpervip 51CTO部落格,原文連結:http://blog.51cto.com/phpervip/1907006,如需轉載請自行聯系原作者

繼續閱讀