Connecting to remote MySQL installations
A question that seems to have poped up a number of time this week over on the MySQL forums is how to connect to MySQL installations on a remote machine, be it on the same network or across the internet.
If you have used Oracle the way to do this is to set up an entry in your tnsnames.ora file, for those that don't know this is a configuration file containing all of the information Oracle needs to connect to database either locally or remotely.
If we are using the SQL*Plus command line client for Oracle we can connect to another server using the following command.
SQLPlus user/password@database
The database portion is in fact a reference to an entry in the tnsnames.ora file which contains the machine name or IP address of the machine and database SID we want to connect to.
In MySQL we don't need to use an additional file to connect to another instance, we simnply add a -h parameter to our call to mysql.
mysql -h hostname -u root -p
This then connects us to the remote database. The -h can be a machine name, webserver or IP address.