注:mysql 5.6,5.7 默认使用utf-8编码,mysql8 默认使用utfmb4编码。
查看当前使用的编码可以使用以下命令:
show variables like 'character%'; show variables like 'collation_%';
可以查到如下信息:
+--------------------------+------------------------------------+ | 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 | D:\program\mysql56\share\charsets\ | +--------------------------+------------------------------------+ +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+
如果要修改成utf-8编码,可以在 mysql 命令行里输入以下内容:
set character_set_connection=utf8; set character_set_database=utf8 ; set character_set_results=utf8 ; set character_set_client=utf8; set character_set_server=utf8; set character_set_system=utf8; set collation_connection=utf8; set collation_database=utf8; set collation_server=utf8;
若要修改成其他编码,把utf8改成相应的编码即可。建议直接使用mysql5.6及以上的版本,默认使用utf-8编码。
使用命令方式只针对当前会话有效,可以修改 my.ini 配置文件里的编码,保存文件后重启mysql服务即可。