2014-05-19 95 views
2

我有以下php代碼連接到我的mysql數據庫。php MySql連接錯誤

mysql_connect("myserver.com" , "root", "redhat","datastore") or die(mysql_error()); 

,當我跑這個代碼,我得到的錯誤說:

Warning: mysql_connect(): Host '10.21.21.10' is not allowed to connect to this MySQL server in C:\xampp\htdocs\inventory\net.php on line 20 
Host '10.21.21.10' is not allowed to connect to this MySQL server 

但myserver.com當我命令做平myserver.com提示IP它給了10.25.15.95

,所以改性的代碼:

mysql_connect("10.21.21.10" , "root", "redhat","datastore") or die(mysql_error()); 

在SAM重複錯誤。

然後,我改變了我的代碼:

mysql_connect("10.25.15.95" , "root", "redhat","datastore") or die(mysql_error()); 

錯誤是

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\inventory\net.php on line 20 
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 

請幫我解決這個..提前

謝謝...

+0

你的遠程服務器不允許你的ip連接。請聯繫您的主機提供商 –

回答

2

在你的MySQL服務器:

的mysql>用mysql;

mysql> CREATE USER'root'@'client_ipaddress'IDENTIFIED BY'redhat';

mysql>在上授予所有特權。 TO'root'@'client_ipaddress'WITH GRANT OPTION;

-2

你在本地運行你的PHP腳本,但你的數據庫服務器是在某個地方(不在本地PC上)。

大多數數據庫服務器都配置爲不允許外部連接(這很好)。

然後根據你的本地計算機的配置,發出的請求也可以由防火牆阻止,...

這就是爲什麼你不能連接。但你首先不應該這樣做。

永遠不要將您的製作數據庫鏈接到您的開發腳本。

只是不!

如果您偶然在本地計算機上寫入錯誤的DELETE ALL查詢,並且意外啓動它,該怎麼辦?哎呀...

您正在使用xampp,它內置了一個mysql服務器,然後使用localhost作爲您的主機連接到它。你的本地計算機上

測試時,一切都遷移到myserver.com主機

+0

OP的數據庫服務器位於本地網絡上(IP範圍以10開頭),因此它很安全。我們做同樣的事情,所以私人網絡上的多個開發人員可以共享一個開發數據庫,​​而不是每次每次更改時都必須更新本地數據庫。 – charliefortune