mysql字符集相关问题_MySQL 字符集相关问题

MySQL安装时指定的字符集为UTF8,但是当我向如下表插入汉字时,总是失败(错误字符)!

DROP TABLE IF EXISTS t_weather;

create table t_weather

(

c_idint unsigned not null auto_increment,

c_provincevarchar(20) not null,

c_cityvarchar(20) not null,

c_city_codechar(5) not null,

c_temperature varchar(20) not null,

c_datedate,

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值