From mi-linux
Revision as of 12:31, 23 September 2010 by In9352 (talk | contribs)
Jump to navigationJump to search

MySQL on mi-linux

MySQL is a very popular, open source, freely available, relational database management system available from

It has been installed on mi-linux and forms the backbone of most web applications/resources available to students, including this wiki!

Students will most likely make advantage of the database server in conjunction with web applications (created in PHP, Java, etc.) to form the data storage/retrieval component of any application.

Registering to use MySQL on mi-linux

YOU DO NOT NEED TO REGISTER to use MySQL on mi-linux unless you wish to create your own database. A number of freely accessible databases exist on the server, which can be viewed through the phpMyAdmin administration application, also installed on the server. Login to phpMyAdmin using "demo" as the account with no password to see the freely available databases.


If you wish to create your own database, follow these steps

1. Visit

2. Login with your university account and password

3. Click "Register for a MySQL Account"

4. Read and agree to the terms and conditions, paying particular attention to the note that all student databases are deleted at the beginning of each academic year unless prior arrangements to keep databases are made with the MySQL administrator via email at


4. You will be sent an email with a RANDOMLY GENERATED PASSWORD and details on how to connect to the admin interface.

5. Once registered, you can administer your database using the phpMyAdmin web interface.

How to Connect to MySQL from a Java Application

If you are looking to connect to your MySQL database from your own Java program there are several steps you need to take. If you have seen a Java-to-database connection demonstrated before you will know that firstly you require the Connection String. In the Data Model the Connection String should be provided as a global variable and initialise the Connection String within the Data Model's constructor such as this:

public class DataModel{
      private String connectionString;
       public DataModel() {
             * Where 0777777 is your student number
             * and where drowssap is your mysql password
            connectionString = "jdbc:mysql://";

This however will still not work as you need to import a mysql connector into your project, to do this follow these instructions:

The SQL Connector needs to be downloading from this link: [1] There's a GB mirror halfway down the list.

Once that zip file has been downloaded and extracted there can be found a jar file inside called something like "mysql-connector-java-5.1.7-bin.jar". This file needs to be imported into the build path of the Project in question.

Rigtht Click Project > Build Path > Configure Built Path > Libraries tab > Add External Jar > Ok

With the Connector imported and with your connectionString in place all that is required now is to produce your Data Model's methods that use the connection connection.

Here is a snippet of code displaying such use; this method assumes the role of querying a table which contains details of Modules containing information such as Module Code, Module Title and Module Leader.

public ArrayList<Module> getModules() {
               ArrayList<Module> ml = new ArrayList<Module>();
               try {
                     // use connection string for myaql mi-linux connection.
                     Connection conn = DriverManager.getConnection(connectionString);
                     Statement stmt = conn.createStatement();
                     /* You will then use stmt to execute your query
                      * and place the results of that query into a resultSet.

It is important to place your connection in a try/catch block to catch any errors with the query or connection itself, it is much more efficient than setting up your own query checks.

More information about Connecting to a database via a java based application can be found in Matthew Burley's CP2120 Software Design Lecture Notes on Relational Database Management System Persistence Data Models - pardon the mouth full.