|
Department of Computing MySQL Server This document covers the use of the MySQL database server running on igor.gold.ac.uk, the Department of Computing Linux server. The MySQL server is available for use by all students in the Department of Computing. Your MySQL AccountAll users of the MySQL service must have an account created on the MySQL server. You can create your own account on the MySQL server and set or change your MySQL password on the Department of Computing intranet: https://www.doc.gold.ac.uk/intranet Click on the "MySQL Account Status" link and follow the instructions. If you have any problems creating your MySQL account, please contact the departmental systems support team. Connecting to MySQL using the mysql CommandThe following shows how user ma007xyz would connect to the MySQL server using mysql at the command-line on the Department of Computing Linux server igor.gold.ac.uk: mysql -h igor -u ma007xyz -p This command tells mysql to connect to the MySQL server on host igor (-h igor) as user ma007xyz (-u ma007xyz) and to prompt for a password (-p). Once connected to the MySQL server, you can create databases and tables and run SQL queries and updates on them. If you wish to connect to a specific database when you start mysql, you can specify the database name at the end of the mysql command-line. For example, to connect to their default initial database (see Creating Databases below), user ma007xyz would type: mysql -h igor -u ma007xyz -p ma007xyz Connecting to MySQL from a PHP ProgramThe following is an example of connecting to a MySQL database from a PHP program on igor: <?php $connection = mysqli_connect( 'igor.gold.ac.uk', 'USERNAME', 'PASSWORD', 'DATABASENAME', 'DATABASEPORT' ); if(mysqli_connect_errno()) { die("Database connection failed: " . mysqli_connect_error() . " (" .mysqli_connect_errno() . ")" ); } // Connection successful, continue processing... ?> Notes:
Connecting to MySQL from a Java ProgramYou can also connect to the MySQL server from your Java programs on igor. To do this, your program will need to load the MySQL JDBC driver package, which is done by the following method call: Class.forName("com.mysql.jdbc.Driver"); You will also need to specify the URL for the connection, which will be something like this: jdbc:mysql://igor.gold.ac.uk/mydatabase Connecting to MySQL from the InternetTo connect directly to the MySQL server on igor.gold.ac.uk via the internet (ie. from a computer not directly connected to the Goldsmiths network), you should configure your MySQL client program to use port 3307 instead of the default MySQL port 3306. For example, to use the mysql command included with a MySQL installation on your own computer to connect to a database on igor called mydatabase using the MySQL username ma007xyz: mysql -h igor.gold.ac.uk -P 3307 -u ma007xyz -p mydatabase Changing Your PasswordAs an alternative to changing your MySQL password on the Department of Computing intranet, you can also change your password from within MySQL itself. To change your password, type the following at the mysql prompt: SET PASSWORD=PASSWORD('new_password'); This will set your password to new_password (you should replace new_password with the password that you want to set). Creating DatabasesWhen your MySQL account is first created, a default initial database is also created for you using your username as the database name. For example, user ma007xyz will initially own a single empty database called ma007xyz. You can create as many additional databases as you wish, using your username followed by an underscore as a prefix to the database name. For example, user ma007xyz might create two additional databases, as follows: create database ma007xyz_ecommerce;and create database ma007xyz_webdesign; Further InformationFor more general information about MySQL, visit the MySQL website. |