Mysql两数据库(不同结构) 迁移一:基础理解

浏览:6685 发布日期:2017/04/27 分类:技术分享 关键字: mysql迁移,mysql搬迁
概述:

工作需求,需要把老版本网站的数据迁移到新网站数据库里。由于两个数据库结构不同,不能直接导入。因此要进行搬迁工作

软件:Navicat

目前我知道的迁移数据有两种,

第一种:建立视图。

原理:拿到“老数据的sql语句”,插入到新数据表里面。 “老数据的sql语句”是指通过建立视图,进行表字段名进行匹配导出数据也就是sql语句。如,INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (1, 1, 'xuziang', '0', '2016-11-1 11:34:37', '2016-11-1 11:34:37', 10, 0, 0, 1);
INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (2, 2, 'wangliliyou', '2', '2016-11-1 12:05:14', '2016-11-1 12:05:14', 10, 0, 0, 1);
INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (3, 3, '13714482984', '19.71', '2016-11-1 13:00:30', '2016-11-1 13:00:30', 10, 0, 0, 1);
INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (9232, 9232, '13986604666', '0', '2016-12-1 14:58:51', '2016-12-1 14:58:51', 10, 0, 0, 1);
INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (5, 5, '13129584297', '18', '2016-11-1 15:08:19', '2016-11-1 15:08:19', 10, 0, 0, 1);
INSERT INTO `cjdl_account` (`account_id`, `user_id`, `user_name`, `amount`, `time_create`, `time_update`, `account_state`, `account_type`, `is_delete`, `data_version`) VALUES (6, 6, 'bubbly317', '43.26', '2016-11-1 15:09:27', '2016-11-1 15:09:27', 10, 0, 0, 1);
我们要做的就是拿到这样的sql语句,把它Insert到新数据表里面,这样就能完成mysql数据迁移。


第二种:新增数据 。

原理:先获取某数据库表的全部数据,然后数据进行大组合。最后结构如
Insert 'order_info' ('新表名字段') value('旧表数据'),多条数据插入就行了。

操作演示
步骤一
建立两个不同结构表table1(旧数据表),table2(新数据表)



步骤二
建立视图。在table1 里面建立部分数据,当测试使用。后面过程如图


建立视图的目的:取table1(旧)数据,并进行字段名称转换(匹配table2字段),方便table2导入。


下一步,点击保存,并且取名。


注意:取名字的不是随便乱取,名称要与新数据表名一直才行。 为什么呢?因为会出现,表名不存在的错误。

正确:INSERT INTO `order_info`() value ()错误:因为在table2里面并没有表order_xxx的存在,所以你的Insert没有用的。INSERT INTO `order_xxx`() value ()视图建立成功,然后就是导出数据,来获取Insert语句了




成功完成以上步骤,会拿到一个order_info.sql的文件,如

这里面的sql语句,就是我们需要的了。

进行table2操作,把拿到的sql语句,放到“查询编译器”,里面,然后直接运行


提示成功



这样数据就进入到table2的表里面了。




Thinkphp5高级交流群:101766150

Mysql数据库(不同结构) 迁移二:常用的sql语句
http://zhouzhongjie.com/news/51.html
最佳答案
评论( 相关
后面还有条评论,点击查看>>