mysql5.7中解决中文乱码的问题

2/13/2017来源:SQL技巧人气:1480

一、打开MySQL控制台,输入命令show variables like 'character%';

  显示如下:

  +--------------------------+-------------------------------------------+ | Variable_name      | Value                   | +--------------------------+-------------------------------------------+ | character_set_client   | latin1                  | | character_set_connection | latin1                  | | character_set_database  | utf8                   | | character_set_results  | latin1                  | | character_set_server   | utf8                   | | character_set_system   | utf8                   | | character_sets_dir    | C:\MySQL\MySQL Server 5.0\share\charsets\ | +--------------------------+-------------------------------------------+

二、修改my.ini文件

  [client]

  default-character-set=utf8

  [mysqld]   default-storage-engine=INNODB   character-set-server=utf8   collation-server=utf8_general_ci

三、重启后使用第一步的命令查看,如下:

  +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 还有character_set_database和character_set_server的默认字符集还是latin1。

四、输入命令:set names utf8;

  重启后,使用第一步命令查看:

+--------------------------+------------------------------------------------+ | 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 | C:\wamp64\bin\mysql\mysql5.7.9\share\charsets\ | +--------------------------+------------------------------------------------+

除了character_set_filesystem是binary外,其他都是utf8了,

这样在web端也设置成utf8编码就可以正常输入数据库了。