Saturday 10 December 2011

select database()

The select database() command lets you see which database you are using. When you first login to mysql, you are not using a database so the query returns a null:
 
mysql> select database ();
+-------------+
| database () |
+-------------+
| NULL        |
+-------------+
1 row in set (0.01 sec)

mysql>

You can choose a database with the use command. Unlike other commands, it seems to work equally well with or without a semi colon at the end:
  
mysql> use test
Database changed
mysql> use test;
Database changed
mysql>

After that, if you run the query again, it shows which database you have chosen:

mysql> select database();
+------------+
| database() |
+------------+
| test       |
+------------+
1 row in set (0.02 sec)

mysql>

No comments: