2 linux的mysql權(quán)限錯(cuò)誤導(dǎo)致看不到mysql數(shù)據(jù)庫2018-05-09

轉(zhuǎn)自:http://www.blogjava.net/jelver/archive/2015/03/22/423715.html
今天早上收到朋友的信息說他家的數(shù)據(jù)庫被人干了,很是緊張,但是后面逐步排除,發(fā)現(xiàn)mysql安裝目錄下的數(shù)據(jù)文件都是正常,從linux歷史執(zhí)行命令日志來看也沒有跡象表面是被人搞,同時(shí)mysql的錯(cuò)誤log里面只有些不穩(wěn)定的日志。最后搜索到兩篇這樣的文章,確定的確是權(quán)限這個(gè)問題導(dǎo)致的,但是為什么服務(wù)突然會(huì)有這種現(xiàn)象,目前還是查看中,同時(shí)整理下這兩篇文章,希望能夠幫到其他人。

參考的原文:
http://www.yebihai.com/kuangjiaxitong/linux/801.html
http://www.unixdo.com/DataBase/1909.html](http://www.unixdo.com/DataBase/1909.html

[root@localhost ~]# mysql -uroot -p123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
只顯示這個(gè)兩個(gè)數(shù)據(jù)庫,看不到mysql數(shù)據(jù)庫

解決方法:
此問題實(shí)際上是用戶沒有權(quán)限:

1. 關(guān)閉mysql,service mysqld stop
2. 啟動(dòng)mysql: mysqld_safe --skip-grant-tables
3. 再打開一個(gè)ssh連接服務(wù)器,進(jìn)行mysql操作
  [root@localhost ~]#cd /usr/local/mysql/bin/
  [root@localhost bin]#./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>show databases;
在這個(gè)模式下是可以看到mysql數(shù)據(jù)庫的。

在數(shù)據(jù)庫名mysql下的user表中,修改相應(yīng)權(quán)限,比如:
mysql>use mysql;

insert into user values('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', '', '', '');

如果已經(jīng)存在了host為localhost的記錄,則先刪除該記錄,delete from user where host='localhost';
然后再進(jìn)行操作。
insert into user values('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', '', '', '');
 
操作完成后,將兩個(gè)ssh連接都關(guān)閉,然后再重新連接一個(gè)ssh,啟動(dòng)mysql,service mysqld start,然后用mysql命令連接mysql數(shù)據(jù)庫
  [root@localhost ~]#mysql -uroot -p
  密碼為空。
 [如果此時(shí)還連接不上,再重啟一下mysql就好了,service mysqld restart]。
然后就可以用  [root@localhost ~]#mysqladmin -uroot password 'newpassword' 來設(shè)置密碼了。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容