一个UTF-8编码的表Student,要导入到一个GBK编码的表中,Student表的结构下面所示:
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(10) | NO | | | |
| age | int(11) | NO | | 0 | |
| class | varchar(10) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
SQL语句为:
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '',
`age` int(11) NOT NULL DEFAULT '0',
`class` varchar(10) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
下面要将会这个表里面的内容导入到一个GBK的表中,那么我们首先建立一个表Newstudent
create table newstudent(
id int(11) not null auto_increment,
name varchar(10) character set gbk not null default '',
age int (11) not null default 0,
class varchar(10) character set gbk not null,
primary key(id)
)engine = myisam default character set utf8;
下面执行批量导入SQL语句:
insert into newstudent select * from student
下面查看newstudent 表中的内容
select * from newStudent
| 2 | 中国 | 20 | 0 |
| 3 | boy | 10 | 2 |
| 4 | girl | 10 | 33 |
+----+------+-----+-------+
这样就成功导入了UTF8中的数据到GBK表中