mysql數據庫創建、刪除數據庫
阿新 • • 發佈:2018-01-23
tin clipboard comm 包括 sta 數據庫 comment toc popu
一、創建數據庫(默認字符集和排序規則)
(1)創建數據庫
[sql] view plain copy
- mysql> CREATE DATABASE my_db1;
- Query OK, 1 row affected (0.00 sec)
(2)因為my_db1已經存在,再次創建會報錯
[sql] view plain copy
- mysql> CREATE DATABASE my_db1;
- ERROR 1007 (HY000): Can‘t create database ‘my_db1‘; database exists
(4)加上IF NOT EXISTS就算數據庫已經存在,把原來的覆蓋掉了
[sql] view plain copy
- mysql> CREATE DATABASE IF NOT EXISTS my_db1;
- Query OK, 1 row affected, 1 warning (0.00 sec)
二、創建數據庫包含字符集和排序規則
(1)查看mysql字符集
[sql] view plain copy
- mysql> SHOW CHARACTER SET;
- +----------+-----------------------------+---------------------+--------+
- | Charset | Description | Default collation | Maxlen |
- +----------+-----------------------------+---------------------+--------+
- | big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
- | dec8 | DEC West European | dec8_swedish_ci | 1 |
- | cp850 | DOS West European | cp850_general_ci | 1 |
- | hp8 | HP West European | hp8_english_ci | 1 |
- | koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
- | latin1 | cp1252 West European | latin1_swedish_ci | 1 |
- .......
(2)查看mysql排序規則
[sql] view plain copy
- mysql> SHOW COLLATION;
- +--------------------------+----------+-----+---------+----------+---------+
- | Collation | Charset | Id | Default | Compiled | Sortlen |
- +--------------------------+----------+-----+---------+----------+---------+
- | big5_chinese_ci | big5 | 1 | Yes | Yes | 1 |
- | big5_bin | big5 | 84 | | Yes | 1 |
- | dec8_swedish_ci | dec8 | 3 | Yes | Yes | 1 |
- | dec8_bin | dec8 | 69 | | Yes | 1 |
- | cp850_general_ci | cp850 | 4 | Yes | Yes | 1 |
- | cp850_bin | cp850 | 80 | | Yes | 1 |
- | hp8_english_ci | hp8 | 6 | Yes | Yes | 1 |
- .................
(3)創建數據庫包括字符集和排序規則
[sql] view plain copy
- mysql> CREATE DATABASE IF NOT EXISTS hdu CHARACTER SET ‘gbk‘ COLLATE ‘gbk_chinese_ci‘;
- Query OK, 1 row affected (0.00 sec)
三、刪除數據庫
[sql] view plain copy- mysql> DROP DATABASE my_db1;
- Query OK, 0 rows affected (0.00 sec)
mysql數據庫創建、刪除數據庫