方法如下:
預設情況下MYSQL資料庫的系統資料庫mysql系統表user內使用者許可權只提供localhost本機登陸;
需要更改許可權才能實現遠端連線MYSQL資料庫。
可以通過以下方式來確認:
root#mysql -h localhost -uroot -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; (檢視使用者的許可權情況) mysql> select host, user, password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | localhost | | | +-----------+------+-------------------------------------------+ 4 rows in set (0.01 sec)由此可以看出,只能以localhost的主機方式訪問。
解決方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by 'kdm001' with grant option; (%表示是所有的外部機器,如果指定某一臺機,就將%改為相應的機器名;‘root’則是指要使用的使用者名稱,) mysql> flush privileges; (執行此句才生效,或者重啟MySQL) Query OK, 0 rows affected (0.03 sec) 再次檢視。。 mysql> select host, user, password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | localhost | | | | % | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | +-----------+------+-------------------------------------------+ 4 rows in set (0.01 sec)可以看出已經新增了一個新的使用者
退出,試試效果....
現在可以成功登入了..
來自:51CTO
評論(2)