MYSQL中沒有mysql庫

http://blog.csdn.net/liuyifeng1920/article/details/49818851mysql

今天在安裝mysql數據庫後,想開啓遠程鏈接,發現查詢不到了mysql數據庫自帶的mysql數據庫,是因爲用戶的權限問題致使,解決辦法以下:
[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 |

  +--------------------+

  只顯示這個兩個數據庫,看不到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 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;

  在這個模式下是能夠看到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','','','','',0,0,0,0);

  若是已經存在了host爲localhost的記錄,則先刪除該記錄,delete from user where host='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','','','','',0,0,0,0);

  操做。

  操做完成後,將兩個ssh鏈接都關閉,而後再從新鏈接一個ssh,啓動mysql,service mysqld start,而後用mysql命令鏈接mysql數據庫

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

  密碼爲空。

  [若是此時還鏈接不上,再重啓一下mysql就行了,service mysqld restart]。

  而後就能夠用 [root@localhost ~]#mysqladmin -uroot password 'newpassword' 來設置密碼了。
相關文章
相關標籤/搜索