将UTF-8编码的数据表导入到GBK编码的表中

本文介绍了如何将一个UTF-8编码的Student表成功导入到GBK编码的newStudent表中,通过SQL的INSERT语句实现数据迁移,确保数据完整无误。

一个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表中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值