1. 程式人生 > >mysql數據庫創建、刪除數據庫

mysql數據庫創建、刪除數據庫

tin clipboard comm 包括 sta 數據庫 comment toc popu

一、創建數據庫(默認字符集和排序規則)

(1)創建數據庫

[sql] view plain copy
  1. mysql> CREATE DATABASE my_db1;
  2. Query OK, 1 row affected (0.00 sec)

(2)因為my_db1已經存在,再次創建會報錯

[sql] view plain copy
  1. mysql> CREATE DATABASE my_db1;
  2. ERROR 1007 (HY000): Can‘t create database ‘my_db1‘; database exists

(4)加上IF NOT EXISTS就算數據庫已經存在,把原來的覆蓋掉了

[sql] view plain copy
  1. mysql> CREATE DATABASE IF NOT EXISTS my_db1;
  2. Query OK, 1 row affected, 1 warning (0.00 sec)


二、創建數據庫包含字符集和排序規則

(1)查看mysql字符集

[sql] view plain copy
  1. mysql> SHOW CHARACTER SET;
  2. +----------+-----------------------------+---------------------+--------+
  3. | Charset | Description | Default collation | Maxlen |
  4. +----------+-----------------------------+---------------------+--------+
  5. | big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
  6. | dec8 | DEC West European | dec8_swedish_ci | 1 |
  7. | cp850 | DOS West European | cp850_general_ci | 1 |
  8. | hp8 | HP West European | hp8_english_ci | 1 |
  9. | koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
  10. | latin1 | cp1252 West European | latin1_swedish_ci | 1 |
  11. .......


(2)查看mysql排序規則

[sql] view plain copy
  1. mysql> SHOW COLLATION;
  2. +--------------------------+----------+-----+---------+----------+---------+
  3. | Collation | Charset | Id | Default | Compiled | Sortlen |
  4. +--------------------------+----------+-----+---------+----------+---------+
  5. | big5_chinese_ci | big5 | 1 | Yes | Yes | 1 |
  6. | big5_bin | big5 | 84 | | Yes | 1 |
  7. | dec8_swedish_ci | dec8 | 3 | Yes | Yes | 1 |
  8. | dec8_bin | dec8 | 69 | | Yes | 1 |
  9. | cp850_general_ci | cp850 | 4 | Yes | Yes | 1 |
  10. | cp850_bin | cp850 | 80 | | Yes | 1 |
  11. | hp8_english_ci | hp8 | 6 | Yes | Yes | 1 |
  12. .................


(3)創建數據庫包括字符集和排序規則

[sql] view plain copy
  1. mysql> CREATE DATABASE IF NOT EXISTS hdu CHARACTER SET ‘gbk‘ COLLATE ‘gbk_chinese_ci‘;
  2. Query OK, 1 row affected (0.00 sec)



三、刪除數據庫

[sql] view plain copy
    1. mysql> DROP DATABASE my_db1;
    2. Query OK, 0 rows affected (0.00 sec)

mysql數據庫創建、刪除數據庫