Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

When I run this:

    $dbHost = "";
    $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'@'' (using password: YES) in /home/foo/bar.php on line 9

What settings should I change?

share|improve this question
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@ IDENTIFIED BY 'password for user';
GRANT ALL PRIVILEGES ON foodatabasename.* TO foouser@;
share|improve this answer

Your Answer


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.