副标题[/!--empirenews.page--]
在Windwos上使用命令窗口操作MySQL数据库时,如果命令窗口的字符编码与数据库不一致时,就会出现中文乱码的情况
比如查询会出现中文乱码,或者插入数据会出现错误“ERROR 1366 (HY000): Incorrect string value: 'xD5xC5xC8xFD' for column 'name' at row 1”
- mysql> insert into user(name,gender,age) values('张三','男',22);
- ERROR 1366 (HY000): Incorrect string value: 'xD5xC5xC8xFD' for column 'name' at row 1
- mysql> select * from user;
- +----+----------+--------+-----+---------------------+
- | id | name | gender | age | updated_time |
- +----+----------+--------+-----+---------------------+
- | 1 | zhangsan | M | 22 | 2018-10-31 17:03:25 |
- | 2 | 寮犱笁 | 鐢? | 22 | 2018-11-01 09:01:43 |
- +----+----------+--------+-----+---------------------+
- 2 rows in set (0.00 sec)
这时可以先查看下环境编码配置,我的是utf8,结果是下面这样
- 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:Program FilesMySQLMySQL Server 5.5sharecharsets |
- +--------------------------+---------------------------------------------------------+
- 8 rows in set (0.00 sec)
(编辑:西双版纳站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|