How to run a PHP script which needs to connect to a MySQL at a remote host?

When I run this:

    $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.");

...I get:

    Warning: mysql_connect(): Access denied for user 'root'@'10.1.1.1' (using password: YES) in /home/foo/bar.php on line 9

What settings should I change?

link|improve this question

68% accept rate
feedback

1 Answer

up vote 4 down vote accepted

By default MySQL users are allowed to access databases from localhost only. You need to add access from your IP or all IPs by using GRANT.

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;
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.