CreateDatabase
CreateDatabase语句作用
在MySQL实例上创建指定名称的数据库
CreateSchema的语义一样。
CREATE {DASTABASE |SCHEMA} [IF NOT EXISTS] db_name [create_specification] ...
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name |
[DEFAULT] COLLATE [=] collation_name
-
当被创建的数据库存在且没写明
if not exists子句时,执行会报错。类似情况在create table语句中也同样体现。 -
**
create_specification**指明数据的属性,并存储在文件db.opt中。- **
Character set**n属性指明此库的默认字符集 - **
Collate**指明默认的排序规则
- **
-
创建语句执行完后,会在datadir目录下生成以数据名为名的目录,目录会包含后续所创建的表等。
-
但在版本
Server version: 8.0.13 MySQL Community Server不成功,原因待查#todolist -
mysql> show create database test1; ERROR 1049 (42000): Unknown database 'test1' mysql> show databases; +--------------------+ | Database | +--------------------+ | forlearn | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) [root@mysql data]# ls -ld */ drwxr-x--- 2 mysql mysql 6 Feb 21 17:47 forlearn/ drwxr-x--- 2 mysql mysql 4096 Feb 21 21:31 #innodb_temp/ drwxr-x--- 2 mysql mysql 137 Feb 15 14:37 mysql/ drwxr-x--- 2 mysql mysql 4096 Feb 15 14:37 performance_schema/ drwxr-x--- 2 mysql mysql 27 Feb 15 14:37 sys/ drwxr-x--- 2 mysql mysql 6 Feb 21 21:31 test1/
-
实例
创建库
create database test3;
建同名库
create database test3;
强制创建库
create database if not exists test3;
mysql> create database test3;
Query OK, 1 row affected (0.08 sec)
mysql> create database test3;
ERROR 1007 (HY000): Can't create database 'test3'; 'database exists
mysql> create database if not exists test3;
Query OK, 1 row affected, 1 warning (0.00 sec)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




