title: Create MySQL user and database from PHP
body: <p>Is there a way to create a new MySQL database, a new MySQL user and give the new user privileges on the new database all using PHP?</p>
  
  <p><strong>EDIT</strong> - should be pointed out this is run from 1 server to another, so Server A trying to install a DB/user on Server B</p>
  
  <p>i've got this:</p>
  
  <pre><code>$con = mysql_connect("REMOTE.IP.ADDRESS","root","pass");
  mysql_query("CREATE DATABASE ".$db."",$con)or die(mysql_error());
  mysql_query("GRANT ALL ON ".$db.".* to  ".$user." identified by '".$dbpass."'",$con) or die(mysql_error());
  </code></pre>
  
  <p>but i'm getting an error on the grant query:</p>
  
  <pre><code>"Access denied for user 'root'@'MY.REMOTE.SERVER.HOST.NAME' to database 'dbname'"
  </code></pre>