XClose

Information Services Division

Home
Menu

Unix commands

The mysql command

The mysql command-line tool, or "MySQL Monitor", may be used on Socrates and Plato. The Unix command line options are documented in the Unix man page man mysql. If you type "help" in mysql, it will list the commands that it supports in addition to standard SQL commands. You can also search the MySQL Search website. If you provide an argument to the help command, mysql uses it as a search string to access server-side help from the contents of the MySQL Reference Manual. Use "help contents" to see a list of the help categories.

The following example illustrates the use of the command to examine table people in database ucabwww, owned by user ucabwww:

mysql -h mysql-server.ucl.ac.uk -u ucabwww -p
Enter password: *******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4440 to server version: 3.23.51-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use ucabwww;
Database changed
mysql> describe people;
+-------+---------+------+-----+---------+----------------+
| Field | Type    | Null | Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
| ID    | int(11) |      | PRI | NULL    | auto_increment |
| Name  | text    | YES  |     | NULL    |                |
| Age   | int(11) | YES  |     | NULL    |                |
+-------+---------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> select name,age from people order by name;
+--------+------+
| name   | age  |
+--------+------+
| arthur |   44 |
| fred   |   23 |
| james  |  123 |
| jane   |   56 |
| jill   |   23 |
| john   |   44 |
| mary   |   34 |
| susan  |   35 |
| tony   |   98 |
+--------+------+
9 rows in set (0.00 sec)

mysql> quit
Bye

Other Unix commands

The following Unix commands are also available. Click on the command name for the relevant manual entry:

mysqldumpDump Table Structure and Data
mysqlimportImport Data from Text Files
mysqlshowShow Databases, Tables, and Columns
mysqlcheckTable Maintenance and Crash Recovery
mysqlhotcopyCopy MySQL Databases and Tables
perror Explain Error Codes