2

I have a database that I want to transfer to my remote server from localhost. The file being too big, I wrote the code to copy the table. But the problem the connection is not successful. My code looks like this.

$server_conn=mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if (!$server_conn) {
    die("Server Connection Fail: " . mysqli_connect_error());
} 

Where $db_host is the ip address of my server.

When I load the script the error I get is

Server Connection Fail: Access denied for user db_user@'117.202.126.83' (using password: YES)

The credentials are correct, the host is correct, and the weirdest part is 117.202.126.83 is my IP address.

I don't know how is it ignoring the host and taking my connection IP address for host. Even when I give the db_host as the IP address of my remote server.

Also, I am running the script using Easy PHP 14.1 running APACHE 2.4.7,MYSQL 5.6.15 and PHP 5.4.24.

What am I missing?

UPDATE: I am not sure if I was stupid or if the hostgator instructions were. They ask us to add the cpanel username followed by an underscore before the database name and database username. In the cpanel, the cpanel username is prefixed by force to all user and db names. So in my case, I had the variables as cpanelUsername_cpanelUsername_databaseName and so on.

Thank you guys for your replies

AtulBhatS
  • 181
  • 2
  • 12
  • Have you checked the firewall of the server? Does the server accepts incomming connections? – Rafael Shkembi Jul 09 '16 at 10:40
  • I am on a shared server, and cannot find any firewall options to check. also, it seems to be stuck with my ip address and does not seem to even connect to the remote server. does that happen if the remote server denies incoming connections? – AtulBhatS Jul 09 '16 at 10:51
  • offcourse it happents. Imagine a server that accepts all incomming connections...disaster!! Try to add your ip to the allow list. – Rafael Shkembi Jul 09 '16 at 10:54
  • I guess, I cannot do that because I am on a shared server and I dont see the options in cpanel – AtulBhatS Jul 09 '16 at 10:57
  • try to log in from putty. Do you get any errors? – Rafael Shkembi Jul 09 '16 at 10:58
  • Most shared servers are configured to only allow access from localhost. Check if that is the case here, in that case you have to run your script from that server. If remote access is allowed, you can try the steps describes e.g. [here](http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes), just with your ip, to add a remote user (the permission settings can be host specific). – Solarflare Jul 09 '16 at 12:02
  • @RafaelShkembi I could connect from Putty. The problem was with hostgator instructions. Thanks – AtulBhatS Jul 09 '16 at 19:15
  • I'am glad to here that you have fix your problem. Have a nice day :) – Rafael Shkembi Jul 09 '16 at 19:16

2 Answers2

4

Go to the cpanel where your phpMyAdmin has the access. Click on Remote MySQL Add the access host (Your local IP which is running the script) Then you can get access to remote mysql server. You can then test the connection using MySQL Workbench ()

Go to the cpanel enter image description here

Saibal Roy
  • 413
  • 2
  • 5
  • I have done that. Yet it is showing the same error. My IP address is already added in the whitelist. – AtulBhatS Jul 09 '16 at 18:49
  • Please deactivate your firewall and then try again. May be it is blocking. – Saibal Roy Jul 09 '16 at 18:50
  • hostgator has some instructions about adding the cpanel login name before db name and db username. Even then It is not working. I am getting the same `Access denied for user_dbname@myIPAddress (using password: YES)` – AtulBhatS Jul 09 '16 at 18:51
-2

are you sure you use the proper external database hostname/ip?