Mysql
PHP 和 MySQL 遠端主機
如何執行需要連接到遠端主機上的 MySQL 的 PHP 腳本?
當我執行這個:
$dbHost = "example.com"; $dbUsername = "root"; $dbPassword = "pass"; $dbDatabase = "some_db"; $dbi = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server."); mysql_select_db ($dbDatabase, $dbi) or die ("Could not select database.");
…我得到:
Warning: mysql_connect(): Access denied for user 'root'@'10.1.1.1' (using password: YES) in /home/foo/bar.php on line 9
我應該更改哪些設置?
預設情況下,MySQL 使用者只能從 localhost 訪問數據庫。您需要使用GRANT從您的 IP 或所有 IP 添加訪問權限。
GRANT USAGE ON *.* to foouser@1.2.3.4 IDENTIFIED BY 'password for user'; GRANT ALL PRIVILEGES ON foodatabasename.* TO foouser@1.2.3.4; FLUSH PRIVILEGES;