MySQL Service

RDlab@lsi.upc.edu
"July" "2011"

english Welcome to LSI.

1. Connection to MySQL ServiceL

This document will show you how to establish a connection with the MySQL server. It will also talk about how to access the service in two ways: in graphical mode using phpMyAdmin web environment, or in textual mode (by the command line interface). Finally, some examples about how to connect to the service from PHP and MySQL will be given.

1.1 Service access information

Server name: mysql-rdlab.lsi.upc.edu
Port: 3306

You can get a username and password by mail at rdlab@lsi.upc.edu or by web at http://rdlab.lsi.upc.edu/index.php/en/services/resources-request.html.

NOTE: Database name will be the same as your username.

1.2 Web access

With your username and password you will be able to access the service from the webpage provided by RDlab:

http://phpmyadmin-rdlab.lsi.upc.edu/

Note: Secure connection is also available through the URL:

https://phpmyadmin-rdlab.lsi.upc.edu/

Once in, the page will show a form where you will be asked for your MySQL username and password.

After the data is entered you will access the main page. This interface allows creating tables, deleting them, querying data and modifying information.

1.3 Text mode connection

In order to connect in textual mode (terminal or Command Line Interface) we can type this command while in a Unix system:

mysql -u <username> --host=mysql-rdlab.lsi.upc.edu -p

The command line will answer “Enter password:”, where we should enter our password. Once authenticated, we will be able to execute any command we want by the command line interface.

By using the command “SHOW DATABASES;” we will see that a database named like our username is available. To select it, we will execute the following:

mysql>SHOW DATABASES;
mysql>USE <username>;

1.4 Php connection example

If we want to establish connection from a PHP environment, we can do it by using the next code snippet:

$host = "mysql-rdlab.lsi.upc.edu";
$login_name = "<username>";
$password = "<password>";
$database = "<username>";
MySQL_connect("$host","$login_name","$password") or die("No em puc connectar a la BD");
MySQL_select_db("$database") or die("No puc sel·leccionar la BD");

1.5 Java connection example

n order to establish connection from a java project, it is necessary to download the mysql-connector-java-5.0.8-bin.jar library, add it to our project and import it with the following sentence:

import java.sql.*;

Once done, we should execute the next code inside a try-catch block:

String db_connect_string = “jdbc:mysql://mysql-rdlab.lsi.upc.edu:3306/<username>”;
String db_userid =“<username>”;
String db_password = “<password>”;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(db_connect_string, db_userid,db_password);

1.6 External links

  1. phpMyAdmin Documentation:
    http://www.phpmyadmin.net/home_page/docs.php
  2. MySQL Reference:
    http://dev.mysql.com/
  3. MySQL des de Java:
    http://dev.mysql.com/usingmysql/java/