- Make sure the mysql server is running.
shell> ps aux|grep mysqld
You will see something like
mysql 1105 0.0 0.3 147108 29096 ? Ssl Aug10 0:37 /usr/sbin/mysqld
- Login to mysql server if the mysql server is running
shell> mysql -u user -h host -p
Or, shell> mysql -u user -h localhost -D dbname -p
Then, input the password.
For example, shell> mysql -u root -h localhost -p
Or
shell> mysql -u root -h localhost -D mysql -p
If the '-D' option is used, there is no need to run use
after login.
- After login, check what are the databases:
mysql> show databases;
It will show something like:
+--------------------+
| Database |
+--------------------+
| information_schema |
| citeseerx |
| csx_citegraph |
| mysql |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
- Then, choose one database to link to.
mysql> use testdb;
You will see the information similar to the following one.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
- Check what are the tables inside this database.
mysql> show tables;
You will see similar information as follows.
+------------------+
| Tables_in_testdb |
+------------------+
| student |
+------------------+
1 row in set (0.00 sec)
- Check the definition of a table.
mysql> desc student;
You can see the following information:
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
- You can test a lot of other SQL statements.
- Disconnect from mysql.
mysql> exit;