create database zzjz CHARACTER SET gbk COLLATE gbk_chinese_ci; create table zz_employees (employeeid int unsigned not null auto_increment primary key,name varchar(13) not null,updatetime datetime) CHARACTER SET gbk COLLATE gbk_chinese_ci; - create table zz_configitems(itemid int unsigned not null auto_increment primary key,itemname varchar(12) not null) CHARACTER SET gbk COLLATE gbk_chinese_ci;
- create table zz_items(itemid int unsigned not null ,employeeid int unsigned not null,item varchar(200) not null,primary key (itemid) ,
- FOREIGN KEY (itemid) REFERENCES zz_configitems(itemid) ON UPDATE CASCADE,FOREIGN KEY (employeeid) REFERENCES zz_employees(employeeid) ON UPDATE CASCADE ) CHARACTER SET gbk COLLATE gbk_chinese_ci;
-
也可以在创建表的时候指定gbk的编码。
当然,也可以通过如下指令修改数据库的字符集
- alter database da_name default character set 'charset'.
客户端以 gbk格式发送 ,可以采用下述配置:
- SET character_set_client='gbk'
- SET character_set_connection='gbk'
- SET character_set_results='gbk'
以上介绍了pyh mysql编程中数据表出现中文乱码问题的解决方法,希望对大家有所帮助。 |