• MySQL数据库的创建(详细)


    MySQL数据库的创建:(借鉴)

    创建数据库设置编码方式:

    CHARACTER SET :指定数据库采用的字符集,注意utf8不能携程utf-8

    COLLATE :指定数据库字符集的排序规则,utf8默认排序规则utf8_general_ci(通过shwo character set 查看)

    第一步:确定没有此数据库;【转IF EXISTS 的用法】

    DROP DATABASE IF EXISTS mryb; (IF EXISTS 好像是必须大写小写出错);

    mysql> DROP DATABASE IF EXISTS mryb;
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    第二步:创建数据库:

    CREATE DATABASE  mryb  CHARACTER SET utf8 COLLATE utf8_general_ci;

    mysql> CREATE DATABASE mryb CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)
    

      

    CREATE DATABASE `mryb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;(注意 :`` 是tab上个面的那个键子不是单引号)

    mysql> CREATE DATABASE `mryb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)
    

      

    语句意义划分

    CREATE DATABASE `mryb` :   代表的是创建数据库 mryb。

    DEFAULT CHARACTER SET utf8 :   代表的是将该库的默认编码格式设置为utf8格式。

    COLLATE utf8_general_ci :     代表的是数据库校对规则,utf8_bin将字符串中的每一个字符用二进制数据存储,区分大小写。utf8_genera_ci不区分大小写,ci为case insensitive的缩写,即大小写不敏感。utf8_general_cs区分大小写,cs为case sensitive的缩写,即大小写敏感

    数据库编码格式:

     charset/collation

    显示所有的字符编码:

    SHOW CHARACTER SET;

    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 |
    | latin2   | ISO 8859-2 Central European     | latin2_general_ci   |      1 |
    | swe7     | 7bit Swedish                    | swe7_swedish_ci     |      1 |
    | ascii    | US ASCII                        | ascii_general_ci    |      1 |
    | ujis     | EUC-JP Japanese                 | ujis_japanese_ci    |      3 |
    | sjis     | Shift-JIS Japanese              | sjis_japanese_ci    |      2 |
    | hebrew   | ISO 8859-8 Hebrew               | hebrew_general_ci   |      1 |
    | tis620   | TIS620 Thai                     | tis620_thai_ci      |      1 |
    | euckr    | EUC-KR Korean                   | euckr_korean_ci     |      2 |
    | koi8u    | KOI8-U Ukrainian                | koi8u_general_ci    |      1 |
    | gb2312   | GB2312 Simplified Chinese       | gb2312_chinese_ci   |      2 |
    | greek    | ISO 8859-7 Greek                | greek_general_ci    |      1 |
    | cp1250   | Windows Central European        | cp1250_general_ci   |      1 |
    | gbk      | GBK Simplified Chinese          | gbk_chinese_ci      |      2 |
    | latin5   | ISO 8859-9 Turkish              | latin5_turkish_ci   |      1 |
    | armscii8 | ARMSCII-8 Armenian              | armscii8_general_ci |      1 |
    | utf8     | UTF-8 Unicode                   | utf8_general_ci     |      3 |
    | ucs2     | UCS-2 Unicode                   | ucs2_general_ci     |      2 |
    | cp866    | DOS Russian                     | cp866_general_ci    |      1 |
    | keybcs2  | DOS Kamenicky Czech-Slovak      | keybcs2_general_ci  |      1 |
    | macce    | Mac Central European            | macce_general_ci    |      1 |
    | macroman | Mac West European               | macroman_general_ci |      1 |
    | cp852    | DOS Central European            | cp852_general_ci    |      1 |
    | latin7   | ISO 8859-13 Baltic              | latin7_general_ci   |      1 |
    | utf8mb4  | UTF-8 Unicode                   | utf8mb4_general_ci  |      4 |
    | cp1251   | Windows Cyrillic                | cp1251_general_ci   |      1 |
    | utf16    | UTF-16 Unicode                  | utf16_general_ci    |      4 |
    | utf16le  | UTF-16LE Unicode                | utf16le_general_ci  |      4 |
    | cp1256   | Windows Arabic                  | cp1256_general_ci   |      1 |
    | cp1257   | Windows Baltic                  | cp1257_general_ci   |      1 |
    | utf32    | UTF-32 Unicode                  | utf32_general_ci    |      4 |
    | binary   | Binary pseudo charset           | binary              |      1 |
    | geostd8  | GEOSTD8 Georgian                | geostd8_general_ci  |      1 |
    | cp932    | SJIS for Windows Japanese       | cp932_japanese_ci   |      2 |
    | eucjpms  | UJIS for Windows Japanese       | eucjpms_japanese_ci |      3 |
    | gb18030  | China National Standard GB18030 | gb18030_chinese_ci  |      4 |
    +----------+---------------------------------+---------------------+--------+
    41 rows in set (0.00 sec)
    

    查看创建数据库的指令并查看数据库使用的编码:

    SHOW CREATE DATABASE mryb;

    mysql> SHOW CREATE DATABASE mryb
        -> ;
    +----------+---------------------------------------------------------------+
    | Database | Create Database                                               |
    +----------+---------------------------------------------------------------+
    | mryb     | CREATE DATABASE `mryb` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    +----------+---------------------------------------------------------------+
    1 row in set (0.00 sec)
    

     修改数据库编码:

    ALTER DATABASE  mryb CHARACTER SET utf8 COLLATE utf8_general_ci;

    mysql> ALTER DATABASE mryb CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.01 sec)

    ALTER DATABASE mryb CHARACTER  SET GBK COLLATE gbk_chinese_ci;

    mysql> ALTER DATABASE mryb CHARACTER SET GBK COLLATE gbk_chinese_ci;
    Query OK, 1 row affected (0.01 sec)

    查看数据库编码

    格式:SHOW VARIABLES LISK '%校对编码段%';

    代码:SHOW VARIABLES LIKE '%char%';

    mysql> SHOW VARIABLES LIKE '%char%';
    +--------------------------+---------------------------------------------------------+
    | Variable_name            | Value                                                   |
    +--------------------------+---------------------------------------------------------+
    | character_set_client     | gbk                                                     |
    | character_set_connection | gbk                                                     |
    | character_set_database   | latin1                                                  |
    | character_set_filesystem | binary                                                  |
    | character_set_results    | gbk                                                     |
    | character_set_server     | latin1                                                  |
    | character_set_system     | utf8                                                    |
    | character_sets_dir       | C:Program FilesMySQLMySQL Server 5.7sharecharsets |
    +--------------------------+---------------------------------------------------------+
    8 rows in set, 1 warning (0.00 sec)

    另一个:

    另一个修改方法就是找到MySQL文件的MY.INI.

  • 相关阅读:
    面试题汇总--1
    行内元素与块级元素
    前端面试题整理---JS基础
    springmvc处理一个请求的全流程
    反射+动态代理+类加载+JVM
    json注解及序列化
    加密
    Thread setUncaughtExceptionHandler
    RunTime.getRunTime().addShutdownHook 添加钩子
    MySQL日志
  • 原文地址:https://www.cnblogs.com/wanghlblog/p/14028991.html
Copyright © 2020-2023  润新知