database

2019-01-18  本文已影响0人  圼_2514

1.查看所有database
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
2.创建database
2.1 创建不存在的database
mysql> create database testdb;
Query OK, 1 row affected (0.01 sec)
2.1 创建已存在的database
mysql> create database testdb;
ERROR 1007 (HY000): Can't create database 'testdb'; database exists
2.3 如果存在不创建,不存在才创建
2.3.1 已存在
mysql> create database if not exists testdb;
Query OK, 1 row affected, 1 warning (0.00 sec)
2.3.2 不存在
mysql> create database if not exists testdb;
Query OK, 1 row affected (0.00 sec)

3.删除database
3.1 删除已存在的database
mysql> drop database testdb;
Query OK, 0 rows affected (0.00 sec)
3.2 删除不存在的database
mysql> drop database testdb;
ERROR 1008 (HY000): Can't drop database 'testdb'; database doesn't exist
3.3 存在才删除
mysql> drop database if exists testdb;
Query OK, 0 rows affected, 1 warning (0.00 sec)

上一篇下一篇

猜你喜欢

热点阅读