Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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