当前位置:  开发笔记 > 后端 > 正文

无法在MySQL 5.7中更改字符集(从latin到utf8)

如何解决《无法在MySQL5.7中更改字符集(从latin到utf8)》经验,为你挑选了1个好方法。



1> Aleksey Byko..:

设置UTF-8 character setcollationMySQL服务器:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

然后按i并添加以下内容:

...
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
...

按下Esc然后:w:q!

然后重启服务器:

sudo /etc/init.d/mysql restart

检查您的配置:

mysql> show variables like "%character%"; 


+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

mysql> show variables like "%collation%";


+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

设置UTF-8 character set以及collation数据库和表:

创建数据库时明确指定它:

CREATE DATABASE some_database CHARACTER SET utf8 COLLATE utf8_general_ci;

检查您的配置:

mysql> SHOW CREATE DATABASE ... 
mysql> SHOW CREATE TABLE ... 

推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有