PDA

View Full Version : how do i remotely access mysql ?


jasonc310771
09-04-2009, 07:26 PM
i currently use...

$host = "localhost";
$login = "mysite_mylogin";
$password = "password";
$base = "mysite_database";
$db = @mysql_connect($host, $login, $password);
@mysql_select_db($base);

and wish to access my backup database on a completely different server should my main one be down for some reason.

i have created a page that will show that the site is down for maintenance and to come back later!

not ideal but need to update my site to allow for this problem.

can someone please advise and i have tried to find out on google but only find things about SSH access, is this what i need ?

ckeyrouz
09-04-2009, 07:35 PM
make sure to change the variable host to the IP or name of the server as follows:

$host = "192.168.5.5";
or
$host="www.myserver.com"


If you need to use the name of the server make sure it is accessible through DNS.

jasonc310771
09-04-2009, 08:18 PM
hey thank for your help.

i have just tried that and the whole site just stopped working and hanged for like ages.

i also tried the www.mysiteurl.com and that too froze the site.

you say about making sure the DNS is accessable? i do not know what this means, please advise.


i have a Linux server

ckeyrouz
09-04-2009, 08:25 PM
I mean that make sure if you put www.mysiteurl.com it works fine in the browser.
If it works fine in the browser then you can use it in the connection string.

By the way make sure to put the IP of the server on which the backup database is installed and make sure that the mysql there is running.

jasonc310771
09-04-2009, 08:35 PM
my site is currently live and has been for two years, i have just edited the connection file but it did not work.

ckeyrouz
09-04-2009, 08:38 PM
Did you point to the server where the backup database is installed on it?
I mean the variable host contains now the address of the new server ?

Or it is still pointing to the same database?

tomws
09-04-2009, 08:42 PM
MySQL on the other server needs to be configured to listen on the external interface. In some cases (most?), it isn't by default.

By doing that, your data will be open and unencrypted on the wire unless you're using a secure connection.

ckeyrouz
09-04-2009, 08:44 PM
I just remembered a thing I used to do at home.
Keep the connection string as localhost and using a SSH tunnel I could to point to other server.

I have windows OS and I used to install putty (freeware) that allows me to point localhost:3306 to a distant server (configuration is very simple)

For linux bases system here is the link of linux version of putty:
http://linux.softpedia.com/progDownload/PuTTY-Download-347.html