Reputation: 23
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?
Upvotes: 1
Views: 1206
Reputation: 1118
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');
Upvotes: 2
Reputation: 324295
For selective migration like this I strongly recommend using an ETL tool like:
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.
Upvotes: 0