简体   繁体   中英

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 .
I want to do it in 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. 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. 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

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:

  • Pentaho Kettle
  • Talend Studio
  • 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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