默認狀況下Linux內的mysql數據庫mysql,user表內的用戶權限只是對localhost即本機才能登錄。須要更改權限:
以下的方式確認:
root#mysql -h localhost-u mysql -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各類配置信息)
Database changed
mysql> select host,user from user; (查看用戶的權限狀況)
+-------------+-------+
| host | user |
+-------------+-------+
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
6 rows in set (0.02 sec)
由此能夠看出,只能以localhost的主機方式訪問。
解決方法:
![更多...](http://static.javashuo.com/static/loading.gif)
mysql> Grant all privileges on *.* to 'root'@'%' identified by ‘password’with grant option;
(%表示是全部的外部機器,若是指定某一臺機,就將%改成相應的機器名;‘root’則是指要使用的用戶名,)
mysql> flush privileges; (運行爲句才生效,或者重啓MySQL)
Query OK, 0 rows affected (0.03 sec)
mysql> select host,user from user; (再次查看用戶的權限狀況)
+-------------+-------+
| host | user |
+-------------+-------+
| % | mysql |
| % | root |
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
mysql>exit
如今再試試:
root#mysql -h mysql -u root -p
Enter password:******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
就成功鏈接上了。
關於在user表裏使用GRANT語句增添新用戶:(
GRANT語句安裝3個新用戶: monty:能夠從任何地方鏈接服務器的一個徹底的超級用戶,可是必須使用一個口令 ('something'作這個。注意,咱們必須對 monty@localhost和monty@"%"發出GRANT語句。若是咱們增長localhost條目,對localhost的匿名用戶條目在我 們從本地主機鏈接接時由mysql_install_db建立的條目將優先考慮,由於它有更特定的Host字段值,因此以user表排列順序看更早到來。 admin:能夠從localhost沒有一個口令進行鏈接而且被授予reload 和process管理權限的用戶。這容許用戶執行mysqladmin reload、mysqladmin refresh和mysqladmin flush-*命令,還有mysqladmin processlist。沒有授予數據庫有關的權限。他們能在之後經過發出另外一個GRANT語句受權。 dummy:能夠不用一個口令鏈接的一個用戶,可是隻能從本地主機。全局權限被設置爲'N'--USAGE權限類型容許你無需權限就可設置一個用戶。它假定你將在之後授予數據庫相關的權限。 注意: 以上的設置不緊是對本機的用戶使用權限的更改,在全部外部的機器上均可以使用指定的用戶登錄鏈接。當使用mysql-front在windows下管理數據庫時,可能因爲版本的問題有些程序不支持使用密碼,出現如下提示: 1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client 可使用mymanager來管理mysql。