Getting Started With Your MySQL Database

You have been given a database on the EECS server to use for this class. This document describes how to access your MySQL database from a departmental (Hydra) machine, and some tips for using the MySQL interpreter.

Accessing the MySQL interpreter

You can access the mysql interpreter from the department's hydra machines by typing the following bold-faced mysql command:

mysql -h -p databasename -u username
Enter password: password
The second line will be a challenge line issued by the mysql interpreter. You will need to provide the following information:

Changing Your Password

To change your password, go into mysql and at the prompt type:

    set password = password("New Password");

Populating Your Database

To create tables and populate your tables with data, you might want to place all your create and insert commands into a file and then load that file into mysql. You can load a file of commands into mysql with the following mysql command:

    source /home/bvz/cs465/lectures/sql/createdb.sql;
where you replace my filename with your file name. Do not use quotes and you must provide the full pathname of the file.

Other Handy MySql Commands

  1. To list the tables in your mysql database, type:
        show tables;
  2. To see the columns that comprise a relation and their types, use the describe command:
        describe courses;
  3. To exit the MySql interpreter, type:
  4. To execute Unix shell script commands from within SQL (or windows shell script commands on Windows), type \! at the mysql prompt, and then your command. For example:
        mysql> \! clear
    will clear your screen. Similarly,
        mysql> \! ls
    will list the contents of the current directory on a Unix workstation. If it's easier to remember, you can also type system at the mysql prompt, and then your command. For example:
        mysql> system clear

You can find more commands and other help by typing "man mysql" into the unix shell