I have website example.com
, it contains a MySQL server. I have another example.org
, both are different domains. I want to access the MySQL server on example.com
from example.org
. How would it be possible?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You will need to set the remote
example.com
when you call the database connection initialization function. For example:But you will need to check whether
example.com
's MySQL server is set to accept connections from other hosts (see thebind-address
directive in yourmy.cnf
ormy.ini
), and that theusername
you connect with is set to be able to connect from external domains.Consider the following Users page of phpMyAdmin:
It is clear that only user
test
has access from outside domains (%
in the Host field). Not shown on the image, but usertest
has full privilege on the database calledtest
. The other users are bound to the local domain, even though the server is set to accept connections from the outside, when authenticating, users are thrown a denial.You can connect to remote MySQL server. Just have to make sure that the remote server is binding to public address.
Here's how: http://www.howtogeek.com/howto/mysql/switch-mysql-to-listen-on-tcp/
You can connect to any MySQL server wherever it is, as long as it's setup for remote connection.
Depending on your operating system and webserver of choice, the settings will be different, but a good place to start is by (if using linux) looking here:
In this file you will find:
You will change this to the IP address of the server and then restart the mysql daemon.
..and now you can connect remotely ;)