MySQL is a simple, fast relational database which is often used as a "back end" for web applications. We offer MySQL database facilities with all standard accounts.
You will have been supplied with a MySQL host, database name, username, and password when you set up your account. Typically the database name and username will be the same as your UNIX username, but the password will never be the same as your UNIX password. (If you have not been given this login information, then please email email@example.com and we will set up a database for you.)
Once you have the host, database name, username and password, you can connect to the database and check that everything is working:
$ mysql -h host -u username -p database-name Enter password: enter your password; it won't be echoed Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 396905 Server version: x.y.z Copyright ... Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
At this point you can enter SQL commands. There is extensive documentation available on-line.
To use the MySQL database from within a program or script, you will need to make the host, database name, username, and password available in the script. It is normal to put this in a variable or an external included file. You can then use whatever library facilities the language makes available to access the database. For instance, in Perl you should use the DBI module.
my $dbhost = 'host'; my $dbname = 'database-name'; my $dbuser = 'username'; my $dbpass = 'password'; use DBI; my $dbh = DBI->connect("dbi:mysql:host=$dbhost:database=$dbname", $dbuser, $dbpass);
or in PHP,
$link = mysql_connect("host", "username", "password"); mysql_select_db>("database-name", $link);
See documentation for the individual languages for more information.
Connecting to your database remotely
For security reasons, we don't allow users to directly connect an external tool (for instance running on your desktop PC) to the MySQL database servers. However, if you have a shell account you can achieve the same effect by using an SSH tunnel. To do so you need to forward a port on your local machine (say 13306) to port 3306 on the server which hosts your database, going via your shell server. An example command would be:
ssh -N -L 13306:mysql-55.int.mythic-beasts.com:3306 onza.mythic-beasts.com
-N means "don't run a command" and
-L sets up the
port forwarding. Substitute sphinx for onza if that is where your
shell account is hosted.
Alternatively, if you're using Windows, grab a copy of plink (the command-line version of PuTTY) and use the same syntax as above, substituting "plink" for "ssh".
Having done this you can connect an external program to port 13306 on your local machine to access your database on our server. Note that if you are running the mysql monitor program under Unix, you must specify "-h 127.0.0.1" rather than "-h localhost"—if you use the latter, the program will try to make a connection to a Unix socket on the local machine, rather than a local TCP socket.