4

I need to know whether remote database connections are possible in every server? does every host provides the option for remote DB connection? and further this connection will be the second connection of the system. So there will be multiple database connections. How can I check if a host has enabled remote database connections?

1
  • You're not going to get an answer for every server or hosting company. Do you want to remove those sentences? Mar 22, 2012 at 14:40

2 Answers 2

3

Yes, it's possible, both mysql (mysql_connect) and mysqli allow you to specify a host for the connection. However, I suspect you can only check by trying: some hosting services might simply block outgoing connections using a firewall, which may be outside the web host machine and undetectable until you attempt to establish the connection.

If you're connecting to a server outside the same network as the server, it's worth considering turning on SSL.

This is not ideal mysql, since there is nothing to set the SSL options explicitly for your application. At best you can use mysql_options(&mysql->conn,MYSQL_READ_DEFAULT_GROUP, "client");, which will load the configuration from the [client] section of the global MySQL configuration file (on the web server). This can cause problems on a shared host.

If you're using mysqli instead, you should be able to use mysqli::ssl_set.

2

Most shared hosting accounts require you to give your self access to the mysql server. Usually you enter your IP address or a range to grant remote mysql access. Most other servers if you have root access you configure it yourself. You'll have to ask the hosting companies if remote mysql is allowed or if you have to grant your IP or another servers IP access which is connecting to the db

1
  • 1
    Yep, most web hosts restrict access to their database servers to either localhost (if hosted on the web server) or hosts on the same network (if there are dedicated database servers). This is a security best practice as most web hosting database servers have no need to be accessed by any hosts outside the network. However, to access the database for development or administration purposes, I usually just use an SSH tunnel instead of adding my IP to the allowed hosts. This is typically more convenient on connections with dynamic IPs. Mar 22, 2012 at 9:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.