I. Creating a database (default character set and collation)
(1) Create a database
[SQL]View PlainCopy
- mysql> CREATE DATABASE my_db1;
- Query OK, 1 row Affected (0.00 sec)
(2) Because MY_DB1 already exists, create an error again
[SQL]View PlainCopy
- mysql> CREATE DATABASE my_db1;
- ERROR 1007 (HY000): Can' t create database ' MY_DB1 '; Database exists
(4) plus if not exists even if the database already exists, the original cover out
[SQL]View PlainCopy
- mysql> CREATE DATABASE IF not EXISTS my_db1;
- Query OK, 1 row affected, 1 Warning (0.00 sec)
Ii. creating a database containing character sets and collations
(1) View MySQL character set
[SQL]View PlainCopy
- 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) View MySQL collation
[SQL]View PlainCopy
- 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) Create database including character set and collation
[SQL]View PlainCopy
- mysql> CREATE DATABASE IF not EXISTS hdu CHARACTER SET ' gbk ' COLLATE ' gbk_chinese_ci ';
- Query OK, 1 row Affected (0.00 sec)
Third, delete the database
[SQL]View PlainCopy
- mysql> DROP DATABASE my_db1;
- Query OK, 0 rows Affected (0.00 sec)
MySQL database create, delete database