简体   繁体   English

将数据从mysql DB传输到postgresql DB

[英]transfer data from mysql DB to postgresql DB

I have a mysql DB which has 30-40 tables.Now I want to transfer its data into postgresql DB which has different structure than mysql DB.So I want to transfer only some of the columns value into potsgresql . 我有一个具有30-40个表的mysql DB。现在我想将其数据传输到结构与mysql DB不同的postgresql DB中,所以我只想将一些列值传输到potsgresql
I want to do it in windows server. 我想在Windows Server中做到这一点。
How can it be done?Are there any tools for it? 怎么做?有没有工具?

For selective migrations, when you want to replicate data from MySQL to Postgres, the easiest way would be to take advantage of so called data wrappers. 对于选择性迁移,当您要将数据从MySQL复制到Postgres时,最简单的方法是利用所谓的数据包装器。 https://wiki.postgresql.org/wiki/Foreign_data_wrappers https://wiki.postgresql.org/wiki/Foreign_data_wrappers

You would need to create mysql_fwd extension in your Postgres database, define a mysql server and a user mapping. 您将需要在Postgres数据库中创建mysql_fwd扩展,定义一个mysql服务器和一个用户映射。 Then you are able to create "foreign tables", which can be perceived as windows to the external database. 然后,您可以创建“外部表”,可以将其视为外部数据库的窗口。 And you can use them for reading as well as for writing. 您可以将它们用于阅读和写作。

CREATE EXTENSION mysql_fdw;



CREATE SERVER mysql_cms
FOREIGN DATA WRAPPER mysql_fdw
OPTIONS (host '192.168.125.206', port '3306');



ALTER SERVER mysql_cms OWNER TO cmsuser;

CREATE USER MAPPING FOR cmsuser SERVER mysql_cms OPTIONS (username 'cmsuser', password '123456');



CREATE SCHEMA mysql_cms AUTHORIZATION cmsuser;

this is an example SQL command which creates a foreign table 这是创建外部表的示例SQL命令

CREATE FOREIGN TABLE mysql_cms.video(
     id INT,
     artist text,
     title text)
SERVER mysql_cms
     OPTIONS (dbname 'cms', TABLE_NAME 'video');

For selective migration like this I strongly recommend using an ETL tool like: 对于像这样的选择性迁移,我强烈建议使用ETL工具,例如:

  • Pentaho Kettle Pentaho水壶
  • Talend Studio 塔伦工作室
  • CloverETL CloverETL

plus hand-conversion of the schema. 加上手动转换模式。

You could try a DB migration tool like the EasyFrom tool suggested by Tim but I've never been impressed by any of the ones I've used so far. 您可以尝试使用Tim推荐的EasyFrom工具之类的数据库迁移工具,但是到目前为止 ,我从未对它印象深刻。

Another option is to simply do a CSV dump from MySQL using SELECT ... INTO OUTFILE , then use PostgreSQL's COPY command to load the CSV. 另一个选择是使用SELECT ... INTO OUTFILE从MySQL进行CSV转储,然后使用PostgreSQL的COPY命令加载CSV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM