mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database yhq;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| yhq |
+--------------------+
5 rows in set (0.00 sec)
mysql> create database yhq;
ERROR 1007 (HY000): Can't create database 'yhq'; database exists
mysql> create database if not exists yhq;
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| yhq |
+--------------------+
5 rows in set (0.00 sec)
mysql> show databases like 'y_'; #佔位符
Empty set (0.00 sec)
mysql> show databases like 'y__';
+----------------+
| Database (y__) |
+----------------+
| yhq |
+----------------+
1 row in set (0.00 sec)
mysql> show databases like 'y%';
+---------------+
| Database (y%) |
+---------------+
| yhq |
+---------------+
1 row in set (0.00 sec)
mysql> show databases like 'yhq';
+----------------+
| Database (yhq) |
+----------------+
| yhq |
+----------------+
1 row in set (0.00 sec)
mysql> use yhq;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| yhq |
+------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| qhh |
| test |
| yhq |
+--------------------+
6 rows in set (0.00 sec)
mysql> drop database qhh;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database qhh;
ERROR 1008 (HY000): Can't drop database 'qhh'; database doesn't exist
mysql> drop database if exists qhh;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> use yhq;
Database changed