MySQL 字符集相关问题
2011-07-29 16:55
302 查看
MySQL安装时指定的字符集为UTF8,但是当我向如下表插入汉字时,总是失败(错误字符)!
DROP TABLE IF EXISTS t_weather;
create table t_weather
(
c_id int unsigned not null auto_increment,
c_province varchar(20) not null,
c_city varchar(20) not null,
c_city_code char(5) not null,
c_temperature varchar(20) not null,
c_date date,
primary key (c_id)
);
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('湖北', 'WuHan', '57494', '28-37','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('BeiJing', 'BeiJing', '54511', '23-27','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('ShangHai', 'ShangHai', '58367', '28-37','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('GunagDong', 'ShenZhen', '59493', '25-29','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('FuJian', 'XiaMen', '59134', '26-33','2011-7-29');
可能原因:操作系统默认的字符集是GBK,因而使用UltraEdit 编辑汉字时底层保存为GBK字符,当向MySQL插入时就报错了!
因而,改正方法为:将MySQL的默认字符集,改为GBK
查看编码:
show variables like 'collation_%';
show variables like 'character_set_%';
修改默认编码:
进入C:\Program Files\MySQL\MySQL Server 5.0 ,打开 my.ini
修改,default-character-set=gbk
DROP TABLE IF EXISTS t_weather;
create table t_weather
(
c_id int unsigned not null auto_increment,
c_province varchar(20) not null,
c_city varchar(20) not null,
c_city_code char(5) not null,
c_temperature varchar(20) not null,
c_date date,
primary key (c_id)
);
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('湖北', 'WuHan', '57494', '28-37','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('BeiJing', 'BeiJing', '54511', '23-27','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('ShangHai', 'ShangHai', '58367', '28-37','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('GunagDong', 'ShenZhen', '59493', '25-29','2011-7-29');
INSERT INTO t_weather (c_province,c_city,c_city_code,c_temperature,c_date)
VALUES('FuJian', 'XiaMen', '59134', '26-33','2011-7-29');
可能原因:操作系统默认的字符集是GBK,因而使用UltraEdit 编辑汉字时底层保存为GBK字符,当向MySQL插入时就报错了!
因而,改正方法为:将MySQL的默认字符集,改为GBK
查看编码:
show variables like 'collation_%';
show variables like 'character_set_%';
修改默认编码:
进入C:\Program Files\MySQL\MySQL Server 5.0 ,打开 my.ini
修改,default-character-set=gbk
相关文章推荐
- mysql中字符集相关的问题
- mysql 中文字符集相关问题备注
- Mysql使用相关问题(持续更新)
- mysql字符集问题
- MYSQL 字符集问题
- mysql中自增auto_increment功能的相关设置及问题
- mysql索引原理相关问题
- qt、Navicat、mysql连接的相关问题总结
- MYSQL 字符集问题
- mysql相关问题
- MySQL数据库基础-MySQL字符集乱码问题最终解决方案
- oracle中字符集的相关问题
- linux下mysql字符集编码问题的修改
- MYSQL/PHP/XAJAX/PHPMYADMIN字符集问题梳理
- mysql自带加密解密字符集问题
- mysql 修改字符集问题 utf-8
- 解决hibernate向mysql插入中文乱码问题(更改MySQL字符集)
- MySQL相关——MySQL针对varchar排序问题
- 解决hibernate向mysql插入中文乱码问题(更改MySQL字符集)
- mysql免安装版安装配置过程中遇到的问题和相关的解决