我是在ubuntu下使用得mysql.html
當執行下面語句的時候mysql
mysql>insert into role(code,name) values(200,'管理員');linux
出現錯誤 (ERROR 1366 (HY000))。web
查看Mysql默認字符集的相關設置:sql
mysql> SHOW VARIABLES LIKE 'character%';
+--------------------------+---------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |數據庫
若是出現上述狀況則須要更改數據庫編碼:我用到的方法爲:ubuntu
mysql> alter database 數據庫名 charset 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 | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+spa
可是此時再次執行插入命令仍舊出現上述錯誤,經查找發現:還要更改role表的name的字符集。.net
mysql>alter table tb_mgr_role modify name varchar(32) charset utf8
參考博文:
http://blog.csdn.net/webnoties/article/details/17219167