• mysql修改字符集


    1. mysql> show variables like 'character%';
    2. +--------------------------+-------------------------------------------------+
    3. | Variable_name | Value |
    4. +--------------------------+-------------------------------------------------+
    5. | character_set_client | gbk |
    6. | character_set_connection | gbk |
    7. | character_set_database | latin1 |
    8. | character_set_filesystem | binary |
    9. | character_set_results | gbk |
    10. | character_set_server | latin1 |
    11. | character_set_system | utf8 |
    12. | character_sets_dir | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ |
    13. +--------------------------+-------------------------------------------------+
    14. 8 rows in set, 1 warning (0.00 sec)
    15. mysql>

    可以看出database和server都采用了latin1编码,不支持中文,我们需要把它修改为utf-8。

    除了这两个,其它的如下

    1. | character_set_client | utf8 |
    2. | character_set_connection | utf8 |
    3. | character_set_database | utf8 |
    4. | character_set_filesystem | binary |
    5. | character_set_results | utf8 |
    6. | character_set_server | utf8 |
    7. | character_set_system | utf8 |
    8. | character_sets_dir | E:\0Develop\mysql-5.7.15-winx64\share\charsets\

    设置mysql数据库编码

    mysql安装目录下,将 my-default.ini 复制一分保存为 my.ini 
    做如下修改 
    陈科肇

    主要看红色框里的内容

    1. [mysqld]
    2. character-set-server=utf8
    3. collation-server=utf8_general_ci
    4. [mysql]
    5. default-character-set = utf8
    6. [mysql.server]
    7. default-character-set = utf8
    8. [mysqld_safe]
    9. default-character-set = utf8
    10. [client]
    11. default-character-set = utf8

    然后删除你当前的mysql服务,再重新注册mysql服务 
    注:一定要以管理员的权限运行dos命令,且cd到mysql安装目录下的bin目录,再注册mysql服务

    1. C:\Windows\system32>sc delete mysql
    2. [SC] DeleteService 成功
    3. C:\Windows\system32>e: cd
    4. E:\>cd E:\0Develop\mysql-5.7.15-winx64\bin
    5. E:\0Develop\mysql-5.7.15-winx64\bin>mysqld --install mysql --defaults-file="E:\0Develop\mysql-5.7.15-winx64\my.ini"
    6. The service already exists!
    7. The current server installed: E:\0Develop\mysql-5.7.15-winx64\bin\mysqld MySQL
    8. E:\0Develop\mysql-5.7.15-winx64\bin>net stop mysql
    9. MySQL 服务正在停止..服务名无效。
    10. 请键入 NET HELPMSG 2185 以获得更多的帮助。
    11. E:\0Develop\mysql-5.7.15-winx64\bin>mysqld --install mysql --defaults-file="E:\0Develop\mysql-5.7.15-winx64\my.ini"
    12. Service successfully installed.
    13. E:\0Develop\mysql-5.7.15-winx64\bin>

    结果

    启动服务,查看编码

    1. C:\Windows\System32>net start mysql
    2. mysql 服务正在启动 .
    3. mysql 服务已经启动成功。
    4. C:\Windows\System32>mysql -u root
    5. Welcome to the MySQL monitor. Commands end with ; or \g.
    6. Your MySQL connection id is 2
    7. Server version: 5.7.15 MySQL Community Server (GPL)
    8. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    9. Oracle is a registered trademark of Oracle Corporation and/or its
    10. affiliates. Other names may be trademarks of their respective
    11. owners.
    12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    13. mysql> show variables like 'character%';
    14. +--------------------------+-------------------------------------------------+
    15. | Variable_name | Value |
    16. +--------------------------+-------------------------------------------------+
    17. | character_set_client | utf8 |
    18. | character_set_connection | utf8 |
    19. | character_set_database | utf8 |
    20. | character_set_filesystem | binary |
    21. | character_set_results | utf8 |
    22. | character_set_server | utf8 |
    23. | character_set_system | utf8 |
    24. | character_sets_dir | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ |
    25. +--------------------------+-------------------------------------------------+
    26. 8 rows in set, 1 warning (0.00 sec)
    27. mysql>

    数据库实例编码设置

    1. mysql> show create database test;
    2. +----------+-----------------------------------------------------------------+
    3. | Database | Create Database |
    4. +----------+-----------------------------------------------------------------+
    5. | test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ |
    6. +----------+-----------------------------------------------------------------+
    7. 1 row in set (0.00 sec)
    8. mysql> alter database test default character set utf8;
    9. Query OK, 1 row affected (0.00 sec)
    10. mysql> show create database test;
    11. +----------+---------------------------------------------------------------+
    12. | Database | Create Database |
    13. +----------+---------------------------------------------------------------+
    14. | test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    15. +----------+---------------------------------------------------------------+
    16. 1 row in set (0.00 sec)
    17. mysql>

    //查看MySQL数据库服务器和数据库字符集 show variables like '%char%';

    //查看表的字符集 show table status from mysql_db like '%tb_name%'

    //查看表中所有列的字符集 show full columns from tb_name;

    //查看mysql所支持的字符集 show charset;

    ==修改字符集==

    //修改全局字符集

    set character_set_connection=gb2312;

    set character_set_database=gb2312;

    set character_set_results=gb2312;

    set character_set_server=gb2312;

    set character_set_system=gb2312;

    set collation_connection=gb2312;

    set collation_database=gb2312;

    set collation_server=gb2312;

    //修改表的字符集 ALTER TABLE tb_name CONVERT TO CHARACTER SET gb2312;

    //修改字段字符集 alter table tb_name modify column tb_column varchar(30) character set gb2312 not null;

  • 相关阅读:
    第十一章 共用体union和枚举enum
    Java代码审计17之fastjson反序列化漏洞(2)
    一文看懂Ngnix内存池源码 附带详细讲解,清晰结构图
    全球No.1集装箱人工智能企业CIMCAI中集飞瞳,集装箱信息识别铅封号识别API免费,集装箱识别率99.98%高泛化性,全球两千+企业用户使用
    使用numba cuda 加速Python运算
    vue3响应式模块的实现 efffect reactive ref...
    Robust Lane Detection from Continuous Driving
    [足式机器人]Part3 变分法Ch01-2 数学预备知识——【读书笔记】
    71、Spring Data JPA 的 样本查询--参数作为样本去查询数据库的数据,也可以定义查询的匹配规则
    Redis分布式锁实现原理
  • 原文地址:https://blog.csdn.net/aberwang9/article/details/79136976