linux的mysql下看不到mysql數據庫解決方案

[root@localhost ~]# mysql -uroot -p123

Welcome to the MySQL monitor.  Commands endwith ; 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 thebuffer.

mysql>show databases;

+--------------------+
|Database          |
+--------------------+
| information_schema |
|test              |
+--------------------+

只顯示這個兩個數據庫,看不到mysql數據庫

解決方法:

此問題實際上是用戶沒有權限:

1. 關閉mysql,service mysqld stop

2. 啓動mysql: mysqld_safe --skip-grant-tables

3. 再打開一個ssh連接服務器,進行mysql操作

   [root@localhost ~]#mysql

   

Welcome to the MySQL monitor.  Commands endwith ; 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 thebuffer.

mysql>show databases;

在這個模式下是可以看到mysql數據庫的。

在數據庫名mysql下的user表中,修改相應權限,比如:

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', '', '');

如果已經存在了host爲localhost的記錄,則先刪除該記錄,delete from user wherehost='localhost';

然後再進行

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', '', '');

操作。

操作完成後,將兩個ssh連接都關閉,然後再重新連接一個ssh,啓動mysql,service mysqldstart,然後用mysql命令連接mysql數據庫

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

  密碼爲空。

 [如果此時還連接不上,再重啓一下mysql就好了,service mysqldrestart]。

然後就可以用  [root@localhost ~]#mysqladmin -urootpassword 'newpassword' 來設置密碼了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章