MySQL database create, delete database

Source: Internet
Author: User

I. Creating a database (default character set and collation)

(1) Create a database

[SQL]View PlainCopy
    1. mysql> CREATE DATABASE my_db1;
    2. Query OK, 1 row Affected (0.00 sec)

(2) Because MY_DB1 already exists, create an error again

[SQL]View PlainCopy
    1. mysql> CREATE DATABASE my_db1;
    2. 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
    1. mysql> CREATE DATABASE IF not EXISTS my_db1;
    2. 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
  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) View MySQL collation

[SQL]View PlainCopy
  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) Create database including character set and collation

[SQL]View PlainCopy
    1. mysql> CREATE DATABASE IF not EXISTS hdu CHARACTER SET ' gbk ' COLLATE ' gbk_chinese_ci ';
    2. Query OK, 1 row Affected (0.00 sec)



Third, delete the database

[SQL]View PlainCopy
      1. mysql> DROP DATABASE my_db1;
      2. Query OK, 0 rows Affected (0.00 sec)

MySQL database create, delete database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.