MySQL 字符集相关问题
生活随笔
收集整理的這篇文章主要介紹了
MySQL 字符集相关问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
總結
以上是生活随笔為你收集整理的MySQL 字符集相关问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多个iframe同时加载并动态调整大小
- 下一篇: Spring Data JPA 从入门到