mysql error number 2003   

Can't connect to MySQL server xxx.xxx.xxx.xxx (10061)

在ubuntu 9.04中默認(rèn)安裝了mysql,默認(rèn)只能本地訪問,google了一下:

采用

登錄到MySQL服務(wù)器端,在mysql庫下執(zhí)行

grant all on *.* to 'remote'@'172.16.21.39' identified by 'password';

即可

如果要設(shè)置為任何客戶端都可以以root連接的話,可以這么寫:
grant all on *.* to 'root'@'%' identifiied by 'root的密碼'

格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by "密碼"

類似這用方法的整理如下:

1。 改表法。可能是你的帳號(hào)不允許從遠(yuǎn)程登陸,只能在localhost。這個(gè)時(shí)候只要在localhost的那臺(tái)電腦,登入mysql后,更改 "mysql" 數(shù)據(jù)庫里的 "user" 表里的 "host" 項(xiàng),從"localhost"改稱"%"

mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;



2. 授權(quán)法。例如,你想myuser使用mypassword從任何主機(jī)連接到mysql服務(wù)器的話。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;



如果你想允許用戶myuser從ip為192.168.1.3的主機(jī)連接到mysql服務(wù)器,并使用mypassword作為密碼

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

但問題仍沒有解決:

找到 命令   mysql> flush privileges    //使修改生效

                顯示影響了零行。

問題依然沒有解決,重新啟動(dòng)mysql  sudo /etc/init.d/mysql restart

還是不行。

從 http://www.blogjava.net/waterjava/archive/2008/04/27/196385.html

了解到mysql有本機(jī)綁定,找到問題所在。

編輯 /etc/mysql/my.cnf

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1

將”bind-address = 127.0.0.1“注釋
sudo /etc/init.d/mysql restart重啟即可遠(yuǎn)程訪問

問題解決