mysql数据库创建、删除数据库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010889616/article/details/48271933

一、创建数据库(默认字符集和排序规则)

    (1)创建数据库

mysql> CREATE DATABASE my_db1;
Query OK, 1 row affected (0.00 sec)

    (2)因为my_db1已经存在,再次创建会报错

mysql> CREATE DATABASE my_db1;
ERROR 1007 (HY000): Can't create database 'my_db1'; database exists
    (4)加上IF NOT EXISTS就算数据库已经存在,把原来的覆盖掉了

mysql> CREATE DATABASE IF NOT EXISTS my_db1;
Query OK, 1 row affected, 1 warning (0.00 sec)


二、创建数据库包含字符集和排序规则

(1)查看mysql字符集

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排序规则

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)创建数据库包括字符集和排序规则

mysql> CREATE DATABASE IF NOT EXISTS hdu CHARACTER SET 'gbk' COLLATE 'gbk_chinese_ci';
Query OK, 1 row affected (0.00 sec)


三、删除数据库

mysql> DROP DATABASE my_db1;
Query OK, 0 rows affected (0.00 sec)



阅读更多

没有更多推荐了,返回首页