[TOC] # CREATE DATABASE ## 描述 该语句用于创建数据库,并可以指定数据库的默认属性(如数据库默认字符集,校验规则等)。 ## 格式 ~~~ create_database_stmt: CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] database_name [database_option_list] database_option_list: database_option [database_option ...] database_option: [DEFAULT] {CHARACTER SET | CHARSET} [=] charset_name | [DEFAULT] COLLATE [=] collation_name | REPLICA_NUM [=] int_num | PRIMARY_ZONE [=] zone_name | {READ ONLY | READ WRITE} | DEFAULT TABLEGROUP [=] {NULL | table_group_name} ~~~ ## 参数解释 <table data-tag="table" id="table-7yt-fjv-5qv" class="table"><colgroup width="331" span="1" data-tag="col" id="col-7wt-m0a-8sw" colwidth="1*" colnum="1" colname="col1" style="width:50%" class="col"></colgroup><colgroup width="388" span="1" data-tag="col" id="col-ql4-2ml-27i" colwidth="1*" colnum="2" colname="col2" style="width:50%" class="col"></colgroup><thead id="thead-gfh-jcr-d5b" class="thead"><tr id="tr-99c-ip3-u5k"><th id="td-j0i-555-ya6"><p id="p-bgn-fjo-a45"><b>参数</b></p></th><th id="td-4xn-sar-rcf"><p id="p-qb9-a70-rzr"><b>描述</b></p></th></tr></thead><tbody data-tag="tbody" id="tbody-sgf-j3k-tf3" class="tbody"><tr data-tag="tr" id="tr-1lr-24f-6i4" class="tr"><td data-tag="td" id="td-x1y-ykt-a2i" class="td"><p id="p-1xa-95z-dj2">database_name</p></td><td data-tag="td" id="td-r4l-16j-3yn" class="td"><p id="p-9gs-14d-52y">指定要修改属性的数据库名称。如果不指定,会对当前默认数据库进行修改。</p></td></tr><tr data-tag="tr" id="tr-3c0-7ko-08n" class="tr"><td data-tag="td" id="td-km2-oma-gi9" class="td"><p id="p-p28-1ne-kkw">CHARSET charset_name</p></td><td data-tag="td" id="td-5q4-a2p-8bt" class="td"><p id="p-45d-4ci-bcx">指定要修改的字符集。</p></td></tr><tr data-tag="tr" id="tr-1bb-y42-tmo" class="tr"><td data-tag="td" id="td-xc3-4hs-rol" class="td"><p id="p-g0o-0g7-c17">COLLATE collation_name</p></td><td data-tag="td" id="td-bb4-oz8-86t" class="td"><p id="p-uum-u9v-7c3">指定校对规则。</p></td></tr><tr data-tag="tr" id="tr-qf4-k4g-4y3" class="tr"><td data-tag="td" id="td-x9z-p70-sbu" class="td"><p id="p-2u9-t6y-tht">REPLICA_NUM int_num</p></td><td data-tag="td" id="td-kj3-qjo-scu" class="td"><p id="p-wfc-uk8-p3k">指定副本数。</p></td></tr><tr data-tag="tr" id="tr-1o8-jk9-87k" class="tr"><td data-tag="td" id="td-63o-fyt-gcx" class="td"><p id="p-91h-x2y-w43">PRIMARY_ZONE zone_name</p></td><td data-tag="td" id="td-51p-81i-69m" class="td"><p id="p-ltt-x8y-joz">指定主Zone。</p></td></tr><tr data-tag="tr" id="tr-h4z-8qf-hv6" class="tr"><td data-tag="td" id="td-l0c-u8x-ekg" class="td"><p id="p-c8r-ssj-2ga">READ ONLY | READ WRITE</p></td><td data-tag="td" id="td-80g-260-wdc" class="td"><p id="p-myp-0ga-028">设置数据库级只读或读写属性。</p></td></tr><tr data-tag="tr" id="tr-dby-s3b-uhl" class="tr"><td data-tag="td" id="td-989-imw-04q" class="td"><p id="p-072-1nj-h6c">DEFAULT TABLEGROUP table_group_name</p></td><td data-tag="td" id="td-krx-4l1-s6p" class="td"><p id="p-4vk-unn-6p4">设置数据库默认表组信息,NULL表示取消数据库默认表组。</p></td></tr></tbody></table> ## 示例 * 创建数据库 test2,并指定字符集为UTF8。 ~~~ OceanBase(admin@test)>create database test2 default CHARACTER SET UTF8; Query OK, 1 row affected (0.00 sec) ~~~ * 创建读写属性的数据库test3。 ~~~ OceanBase(admin@test)>create database test3 READ WRITE; Query OK, 1 row affected (0.03 sec) ~~~