菜单开关

周梦康 发表于 2018-03-19 1145 次浏览 标签 : Mysql
mysql> show variables like 'character%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 |
| character_set_connection | latin1 |
| character_set_database   | utf8   |
| character_set_filesystem | binary |
| character_set_results    | latin1 |
| character_set_server     | utf8   |
| character_set_system     | utf8   |
| character_sets_dir       |        |
+--------------------------+--------+

解决办法

set character_set_client=utf8;
set character_set_results=utf8;

发现查询的结果不再乱码了。

mysql 系统变量

  • character_set_server:默认的内部操作字符集
  • character_set_client:客户端来源数据使用的字符集
  • character_set_connection:连接层字符集
  • character_set_results:查询结果字符集
  • character_set_database:当前选中数据库的默认字符集
  • character_set_system:系统元数据(字段名等)字符集

tips

SET NAMES 'utf8'等价于

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

评论列表