转载的,我只用了红线以前的部分就ok啦,红线下的供参考。
俺哪宝贝MYSQL5,可不听话,插入汉字也不乖,老报错,俺实在没办法,打了它一顿好了!
mysql> insert into a values('中国');
ERROR 1406 (22001): Data too long for column 'name' at row 1
或者
网上的贴子写的可有好的,俺看了一个ITPUB上的贴很有启发。
俺给它来个前后里外打!
***********************************************************
:前打
建库的时候用GBK,设定字符编码;
mysql> create database testgbk default charset=gbk;
Query OK, 1 row affected (0.02 sec)
mysql> use testgbk;
Database changed
:后打
建表的时候用GBK,设定字会编码
mysql> create table t_gbk(
-> id char(16) NOT NULL)
-> DEFAULT CHARSET=gbk;
Query OK, 0 rows affected (0.05 sec)
==================================================================
:)) 听话了吧!
插入中文数据没问题;
mysql> insert into t_gbk values('中国');
Query OK, 1 row affected (0.03 sec)
/////////////////////////////////////////////////////
显示本地字符集;
mysql> show variables like '%char%';
+--------------------------+---------------------------+
| Variable_name | Value |
+--------------------------+---------------------------+
| character_set_client | gb2312 |
| character_set_connection | gb2312 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gb2312 |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | C:\mysql5\share\charsets\ |
+--------------------------+---------------------------+
8 rows in set (0.00 sec)
///////////////
mysql> show variables like '%char%';
+--------------------------+---------------------------+
| Variable_name | Value |
+--------------------------+---------------------------+
| character_set_client | gb2312 |
| character_set_connection | gb2312 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gb2312 |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | C:\mysql5\share\charsets\ |
+--------------------------+---------------------------+
8 rows in set (0.00 sec)//////////////////////////////////
MYSQL5就是不听话!
要是上面的方法还出错你就!
mysql> set names gbk;
改my.ini二处
[client]
port=3306
default-character-set=gbk
********************
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=gbk
******************
一般的MYSQL5都听话了
注:
要是在日文系统下开发的话,gbk或gbk2312改成 sjis就可以啦!
)