1

It's a simple thing really. But I can't solve it so I'm hoping someone will quickly give me the answer.

I got two separate servers. The MySQL database is hosted on server #1, and the PHP files on that server are running the website by making queries. Now I'd like to have the same content on website #2, by accessing the same database remotely and running the DB queries.

I have given the remote IP access to the DB on server #1. I have copied the same PHP file (which is making the queries on server #1) to server #2 and changed 'localhost' to IP address of that server. The username and the password remained the same.

When I run that PHP file I get a message "Database NOT found".

This is the PHP code which accesses the database on server #1, the same server where the database is:

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "localhost";

And this is the second case, the PHP file on server #2 which is supposed to access the same database:

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "xx.xxx.xxx.xxx"; //IP address of server #1
3
  • 2
    Please post your connection code, feel free to omit the actual hostname/username/password. Also make sure you don't have a firewall blocking access and that the user is configured to be able to access the server remotely. Commented May 24, 2012 at 17:20
  • Posted. As far as I know, firewall is not enabled, unless firewalls are a default feature which is supposed to be switched off. The user is the same as in the first case. Commented May 24, 2012 at 17:30
  • Maybe your question would be more properly worded as: "How to troubleshoot MySQL remote database connection?" - thegeekstuff.com/2010/08/allow-mysql-client-connection Commented May 24, 2012 at 17:33

2 Answers 2

2

You say you've checked the firewall & made sure the remote host is connecting to the machine with the DB so those are out. The easiest thing to check after that is permissions. Remember that permissions are given to user@host & you might have only given access to user@localhost. After that, it's time to take a look at your database configuration.

Sign up to request clarification or add additional context in comments.

2 Comments

This could be the answer, but I'm using cPanel and I don't know how to link users with hosts, I can only add a new user and enter a remote IP separately, but not together. So I do not know does the user oddsnavi_xxx have access from localhost only.
When I ran SHOW GRANTS in phpMyAdmin, in all four results I see user@localhost.
0

What you should do really if you're using Cpanel, is to go to the Remote MySql Under Databases...In the Input field where it ask for allowed connection. just enter the domain name for Server #2, put the same configuration you gave in your question but this time, instead of putting the IP address of Server #1 in Server#2 Php connection code, put the domain name for Server #1. E.g.

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "server#1.com"; //Domain name address of server #1

4 Comments

Doesn't work, with or without www. The problem seems to be that the root user (or the database_xxx user) are allowed to access the DB from localhost only. I don't know how to give that user access from anywhere.
you have to include it without the the "www"...That's why in Server#1 you must specify that rule in the Remote MySql by adding it. Goto Remote MySql - the input field that says "ADD HOST" just enter the domain name of Server#2 there. and in your code above for Server#2 connection for $server -> Add Server#1's domain name there. That should enable you connect remotely to server#1's Database.Make sure that $user_name, $password and $database name are the same thing with Server#1
Doesn't work. The user apparently only has access when logging in from localhost, and I don't know how to change that.
you can request your Host to do that for you.if your control panel accepts only localhost access.one other thing you can do is, in the input field for "ADD HOST" under Remote MySql. use wild card instead to accept any range of IP address. I.e put this symbol there "%" and Add that as the connecting host. Then in your Server#2 php code for $server info, add the domain name of Server#1.Try that and see if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.