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

数据库 专栏收录该内容
19 篇文章 0 订阅

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

    (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)



  • 8
    点赞
  • 0
    评论
  • 14
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值