创建数据库
语法
1 create database [if not exists] 数据库名
2 [default] character set 字符集名
3 [default] collate 校对规则名;
实例
复制代码
1 mysql> create database if not exists demo
2 -> default character set utf8
3 -> default collate utf8_general_ci;
4 Query OK, 1 row affected (0.00 sec)
5
6 mysql>
复制代码
查看数据库的定义声明
语法
1 show create database demo;
查询所有的数据库
语法
1 show databases;
实例
复制代码
1 mysql> show databases;
2 +--------------------+
3 | Database |
4 +--------------------+
5 | information_schema |
6 | demo |
7 | mysql |
8 | performance_schema |
9 +--------------------+
10 4 rows in set (0.00 sec)
11
12 mysql>
复制代码
选择要使用的数据库
语法
1 use demo;
实例
1 mysql> use demo;
2 Database changed
3 mysql>
修改数据库
语法
1 alter database 数据库名
2 [default] character set 字符集名
3 [default] collate 校对规则名;
实例
复制代码
1 mysql> show create database demo;
2 +----------+---------------------------------------------------------------+
3 | Database | Create Database |
4 +----------+---------------------------------------------------------------+
5 | demo | CREATE DATABASE demo /!40100 DEFAULT CHARACTER SET utf8 / |
6 +----------+---------------------------------------------------------------+
7 1 row in set (0.00 sec)
8
9 mysql> alter database demo
10 -> character set gb2312
11 -> collate gb2312_chinese_ci;
12 Query OK, 1 row affected (0.00 sec)
13
14 mysql> show create database demo;
15 +----------+-----------------------------------------------------------------+
16 | Database | Create Database |
17 +----------+-----------------------------------------------------------------+
18 | demo | CREATE DATABASE demo /!40100 DEFAULT CHARACTER SET gb2312 / |
19 +----------+-----------------------------------------------------------------+
20 1 row in set (0.00 sec)
21
22 mysql>
复制代码
删除数据库
语法
1 drop database [if exists] 数据库名;
实例
1 mysql> drop database demo;
2 Query OK, 0 rows affected, 2 warnings (0.00 sec)
3
4 mysql>