- 创建数据库
- CAEATE {DATABASE|SCHEMA}[IF NOT EXISTS] db_name ;这里面{}中的是二选一的,[]中的是不是必须的
- 这里创建的时候可以加上编码方式。
mysql> CREATE DATABASE IF NOT EXISTS maizi3 DEFAULT CHARACTER SET="GBK";//非默认的编码方式 mysql> SHOW CREATE DATABASE maizi3; +----------+----------------------------------------------------------------+ | Database | Create Database | +----------+----------------------------------------------------------------+ | maizi3 | CREATE DATABASE `maizi3` /*!40100 DEFAULT CHARACTER SET gbk */ | +----------+----------------------------------------------------------------+
-
CREATE DATABASE IF NOT EXISTS MAIZI2;
- 查看当前服务器下已有的目录
- SHOW DATABASES|SCHEMAS;
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | maizi1 | | maizi2 | | mysql | | performance_schema | | sys | +--------------------+
- SHOW DATABASES|SCHEMAS;
- 查看指定数据库的定义
- SHOW CREATE DATABASE|SCHEMA db_name;
mysql> SHOW CREATE DATABASE maizi1; +----------+-----------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------+ | maizi1 | CREATE DATABASE `maizi1` /*!40100 DEFAULT CHARACTER SET utf8 */ |
- SHOW CREATE DATABASE|SCHEMA db_name;
- 修改指定数据库的编码方式
- ALTER{DATABASE|SCHEMA} da_name [DEFAULT] CHARACTER SET [=] 编码方式
ALTER DATABASE maizi3 DEFAULT CHARACTER SET utf8; mysql> SHOW CREATE DATABASE maizi3; +----------+-----------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------+ | maizi3 | CREATE DATABASE `maizi3` /*!40100 DEFAULT CHARACTER SET utf8 */ |
- ALTER{DATABASE|SCHEMA} da_name [DEFAULT] CHARACTER SET [=] 编码方式
- 打开指定数据库
- USE db_name;
mysql> USE maizi3; Database changed mysql> SELECT DATABASE();//得到打开的数据库 +------------+ | DATABASE() | +------------+ | maizi2 | +------------+
- USE db_name;
- 删除打开的数据库
- DROP {DATABASE|SCHEMA} db_name;
mysql> DROP DATABASE IF EXISTS maizi3; Query OK, 0 rows affected (0.00 sec) mysql> DROP DATABASE IF EXISTS maizi3; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> SHOW WARNINGS; Empty set (0.00 sec)
- DROP {DATABASE|SCHEMA} db_name;
- 常用的命令
- 查看上一条操作产生的警告:SHOW WARNINGS;
- 得到当前打开的数据库:SELECT DATABASE();