Copy data from MySQL to PostgreSQL
Project description
MySQL to PostgreSQL
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 500k records/min serially.
Usage
usage: mysql2pg [-h] [--parallelism PARALLELISM] [--pg-search-path PG_SEARCH_PATH]
Copy records from MySQL to PostgreSQL
options:
-h, --help show this help message and exit
--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.
- Limiting the tables.
Implementation
-
MySQL tables are discovered.
-
PostgreSQL tables are truncated.
-
PostgreSQL triggers (including foreign keys) are disabled.
-
Records are streamed from MySQL and uploaded to PostgreSQL via the COPY command.
-
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
Built Distribution
File details
Details for the file mysql2pg-1.2.1.tar.gz
.
File metadata
- Download URL: mysql2pg-1.2.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12c9d700ca36277e95100897c89750de7989f4e2906044aeaeeaa768a01c4b63 |
|
MD5 | edfdd21c87b77dd1b32c8cf7eb03d6e2 |
|
BLAKE2b-256 | e368564796d04ef8ba6d19a7bc685f6ff27ed87e6484dc7a8718960314af6862 |
File details
Details for the file mysql2pg-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: mysql2pg-1.2.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907117447eb900ff69c25e7bcf03dfae68c662f695a9b7fd8d6f847b2afb8dcc |
|
MD5 | 9b2a8ff788f68aee0bfd8352e1a8653b |
|
BLAKE2b-256 | dd1f951ace423a019c27519793ea872964df1466ac0e42559067164ca80fec51 |