If you are trying to connect with remote mysql database to perform remote management or connectivity with some web app to add data into the db , and sees the following error
Connection failed: Access denied for user ‘zaib’@’x.x.x.x’ (using password: YES)
OR
Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
Then you need to grant access to the user from any hostname. This is how you add new privilege from mysql command line.
NOTE: Please beware that this is for just example purpose only , and you MUST take good security measures like Strong Password, and allow only specific IP address to access etc.
CREATE USER 'zaib'@'localhost' IDENTIFIED BY 'zaib1234'; GRANT ALL PRIVILEGES ON *.* TO 'zaib'@'localhost' WITH GRANT OPTION; CREATE USER 'zaib'@'%' IDENTIFIED BY 'zaipassword'; GRANT ALL PRIVILEGES ON *.* TO 'zaib'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;
Sample PHP page to test Remote Mysql connection
Now you can test it with sample php page. change the host name of remote mysql server, and the id , password we just created in above steps.
<?php $servername = "remote.mysql.host.ip.or.name"; $username = "zaib"; $password = "zaibpass"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully. Hurraahhhhh/Alhamdolillah"; ?>
Regard’s
Syed Jahanzaib
Filed under: Linux Related
![](http://pixel.wp.com/b.gif?host=aacable.wordpress.com&blog=10450829&post=7475&subd=aacable&ref=&feed=1)