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
總結
以上是生活随笔為你收集整理的mysql字符集相关问题_MySQL 字符集相关问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 隐式锁和显示锁_锁的类型以及
- 下一篇: mysql高性能学习笔记03_MySQL