赞
踩
DDL : Data Definition Language
用途:
用于描述数据库中存储的现实世界实体的语言。即创建数据库和表的结构。
CREATE ALTER DROP TRUNCATE
CREATE {DATABASE | SCHEMA } [ IF NOT EXISTS ] 数据库名称
CREATE DATABASE IF NOT EXISTS mydb3 CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> SHOW CREATE DATABASE mydb1;
±---------±---------------------------------------------------------------+
| Database | Create Database |
±---------±---------------------------------------------------------------+
| mydb1 | CREATE DATABASE mydb1
/*!40100 DEFAULT CHARACTER SET utf8 / |
±---------±---------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql>
mysql>
mysql> SHOW CREATE DATABASE mydb2;
±---------±--------------------------------------------------------------+
| Database | Create Database |
±---------±--------------------------------------------------------------+
| mydb2 | CREATE DATABASE mydb2
/!40100 DEFAULT CHARACTER SET gbk / |
±---------±--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SHOW CREATE DATABASE mydb3;
±---------±---------------------------------------------------------------+
| Database | Create Database |
±---------±---------------------------------------------------------------+
| mydb3 | CREATE DATABASE mydb3
/!40100 DEFAULT CHARACTER SET utf8 */ |
±---------±---------------------------------------------------------------+
1 row in set (0.00 sec)
查询
SHOW DATABASES;
SHOW CREATE DATABASE 数据库名称;
删除
DROP DATABASE 数据库名称;
mysql> SHOW CREATE DATABASE mydb3;
±---------±---------------------------------------------------------------+
| Database | Create Database |
±---------±---------------------------------------------------------------+
| mydb3 | CREATE DATABASE mydb3
/*!40100 DEFAULT CHARACTER SET utf8 */ |
±---------±---------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> DROP DATABASE IF EXISTS mydb3;
Query OK, 0 rows affected (0.02 sec)
mysql> SHOW DATABASES;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mydb1 |
| mydb2 |
| mysql |
| test |
±-------------------+
5 rows in set (0.00 sec)
修改
ALERT
mysql> SHOW CREATE DATABASE mydb1;
±---------±---------------------------------------------------------------+
| Database | Create Database |
±---------±---------------------------------------------------------------+
| mydb1 | CREATE DATABASE mydb1
/*!40100 DEFAULT CHARACTER SET utf8 / |
±---------±---------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> ALTER DATABASE mydb2 CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW CREATE DATABASE mydb2;
±---------±---------------------------------------------------------------+
| Database | Create Database |
±---------±---------------------------------------------------------------+
| mydb2 | CREATE DATABASE mydb2
/!40100 DEFAULT CHARACTER SET utf8 */ |
±---------±---------------------------------------------------------------+
1 row in set (0.00 sec)
来源:
http://www.360doc.com/content/20/0123/19/57605256_887619259.shtml
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。