mysql connection from a different domain

2019-02-19 10:09发布

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?

3条回答
老娘就宠你
2楼-- · 2019-02-19 10:45

You will need to set the remote example.com when you call the database connection initialization function. For example:

mysqli_connect("example.com", 'username', 'password', 'database name');

But you will need to check whether example.com's MySQL server is set to accept connections from other hosts (see the bind-address directive in your my.cnf or my.ini), and that the username you connect with is set to be able to connect from external domains.

Consider the following Users page of phpMyAdmin: Example user privilege list

It is clear that only user test has access from outside domains (% in the Host field). Not shown on the image, but user test has full privilege on the database called test. 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.

查看更多
聊天终结者
3楼-- · 2019-02-19 10:47

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/

查看更多
疯言疯语
4楼-- · 2019-02-19 10:47

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:

/etc/mysql/my.cnf

In this file you will find:

bind-address: 127.0.0.1

You will change this to the IP address of the server and then restart the mysql daemon.

..and now you can connect remotely ;)

查看更多
登录 后发表回答