您的位置:首页技术文章
文章详情页

mysql配置没问题,但不显示中文;

【字号: 日期:2022-06-10 08:45:26浏览:45作者:猪猪

问题描述

mysql> show variables like "%colla%";+----------------------+-----------------+| Variable_name| Value |+----------------------+-----------------+| collation_connection | utf8_general_ci || collation_database | utf8_general_ci || collation_server | utf8_general_ci |+----------------------+-----------------+

mysql> show variables like "%char%";+--------------------------+-----------------------------------------------+| 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:phpStudyPHPTutorialMySQLsharecharsets |+--------------------------+-----------------------------------------------+

mysql> create table emp3( -> `id` int(11) NOT NULL AUTO_INCREMENT, -> `username` varchar(50) NOT NULL, -> `balance` float NOT NULL, -> `province` varchar(20) NOT NULL, -> `age` tinyint(3) unsigned NOT NULL, -> `sex` tinyint(4) NOT NULL, -> PRIMARY KEY (`id`) -> ) ENGINE=InnoDB CHARSET=utf8;Query OK, 0 rows affected (0.03 sec)

mysql配置没问题,但不显示中文;

问题解答

回答1:

因为cmd命令行的字符编码是gbk,所以你插入的是gbk编码的数据,而你的表是utf8编码,所以插入会乱码,你可以试建一个gbk编码的数据表,执行set names gbk;然后再命令行里插入数据