Skip to main content

Copy data from MySQL to PostgreSQL

Project description

MySQL to PostgreSQL

PyPI Publish

Copy rows from MySQL to PostgreSQL quickly.

Example

Example
export PGHOST=localhost
export PGUSER=postgres
export MYSQL_DATABASE=example
export MYSQL_HOST=127.0.0.1
export MYSQL_USER=root

docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE -p 3306:3306 --name mysql --rm mysql
mysql -D "$MYSQL_DATABASE" -u "$MYSQL_USER" <<EOF
CREATE TABLE example (a int, b text);
INSERT INTO example (a, b) VALUES (1, 'a'), (2, 'b'), (3, 'c');
EOF

docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 --name postgres --rm postgres
psql <<EOF
CREATE TABLE example (a int, b text);
EOF

mysql2pg

psql <<EOF
TABLE example;
EOF

docker stop mysql
docker stop postgres
INFO      Found 1 tables
INFO      Truncating 1 tables
INFO      Copying table example
INFO      Copied 3 rows to table example (0.00s)

 a | b
---+---
 1 | a
 2 | b
 3 | c
(3 rows)

Install

pip3 install mysql2pg

Documentation

Mysql2pg copies records from MySQL tables to existing PostgreSQL tables.

Mysql2pg also resets sequences, based on the maximum column value.

Performance is limited by network bandwidth, database resources, record size, and parallelism. In anecdotal usage, performance is 1m+ records/min serially.

Usage

usage: mysql2pg [-h] [--log-level {critical,error,warning,info,debug}] [--parallelism PARALLELISM]
                [--pg-search-path PG_SEARCH_PATH]
                [tables ...]

Copy records from MySQL to PostgreSQL

positional arguments:
  tables

options:
  -h, --help            show this help message and exit
  --log-level {critical,error,warning,info,debug}
  --parallelism PARALLELISM
                        Number of tables to process in parallel (default: 10)
  --pg-search-path PG_SEARCH_PATH
                        PostgreSQL search path (default: None)

Supported

  • Parallelism
  • Foreign keys
  • PostgreSQL schema

Not supported

  • Creating PostgreSQL tables. If you need to convert schema, look at other tools like mysql2postgres.

Implementation

  1. MySQL tables are discovered.

  2. PostgreSQL tables are truncated.

  3. PostgreSQL triggers (including foreign keys) are disabled.

  4. Records are streamed from MySQL and uploaded to PostgreSQL via the COPY command.

  5. Sequences are discovered and reset based on the maximum value in the column.

Tables are processed in parallel.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mysql2pg-1.4.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

mysql2pg-1.4.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file mysql2pg-1.4.0.tar.gz.

File metadata

  • Download URL: mysql2pg-1.4.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for mysql2pg-1.4.0.tar.gz
Algorithm Hash digest
SHA256 12236911e822c50d1e8051d947b4936fac89adee6e9848ae1b7b6e9a45368b48
MD5 265f8ba7d79c22370f74c4ecb2186aa1
BLAKE2b-256 17e128ea8fd01c22bef35873163f54e7b329ec81f1aded4265a6339ba0d5212c

See more details on using hashes here.

File details

Details for the file mysql2pg-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: mysql2pg-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for mysql2pg-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c7991a84632616abfe41d20d72be020b5e8dc2df32a5d0d2d60a31abfe2564a
MD5 1fc29b5da07d02103003ccba93fcf562
BLAKE2b-256 86dbd3839cf4436072d8f83179b3ce5a39974c11111ab7b96eb69101b4b862c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page