数据库的创建

时间:2021-12-13 02:02:38

创建数据库
CREATE DATABASE 数据库名称;
mysql> CREATE DATABASE itcase;
Query OK, 1 row affected
查看数据库
SHOW DATABASE;
mysql> SHOW DATABASES;
--------------------
| Database |
--------------------
| information_schema |
| itcase |
| itsa |
| mysql |
| performance_schema |
| test |
--------------------
6 rows in set
查看某个已经创建的数据库信息
SHOW CREATE DATABASE 数据库名称
mysql> SHOW CREATE DATABASE itcase;
---------- ----------------------------------------------------------------
| Database | Create Database |
---------- ----------------------------------------------------------------
| itcase | CREATE DATABASE `itcase` /*!40100 DEFAULT CHARACTER SET gbk */ |
---------- ----------------------------------------------------------------
1 row in set
修改数据库编码
ALTER DATABASE 数据库名称 DEFAULT CHARACTER SET 数据库编码;
数据库编码有gbk和utf8

mysql> ALTER DATABASE itcase DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected

查看修改后的数据库编码
mysql> SHOW CREATE DATABASE itcase;
---------- -----------------------------------------------------------------
| Database | Create Database |
---------- -----------------------------------------------------------------
| itcase | CREATE DATABASE `itcase` /*!40100 DEFAULT CHARACTER SET utf8 */ |
---------- -----------------------------------------------------------------
1 row in set
删除数据库
DROP DATABASE 数据库名称;
mysql> DROP DATABASE itcase;
Query OK, 0 rows affected
查看数据库是否删除
mysql> SHOW DATABASES;
--------------------
| Database |
--------------------
| information_schema |
| itsa |
| mysql |
| performance_schema |
| test |
--------------------
5 rows in set