Skip to main content

python-mysql2postgresql

Installation - pure Python

pip install python-mysql2postgresql

Usage via Python file

from mysql2postgresql import mysql2postgresql

a = mysql2postgresql()

# connect MySQL server
a.connect_mysql(
    host='localhost',
    port='3306',
    user='root',
    passwd='',
    db='database_name'
)

# connect PostgreSQL server
a.connect_postgresql(
    host='localhost',             
    port=5432,
    user='postgres',                                
    password='postgres',                     
    database='database_name'
)  

# shortlist of tables to copy data from -> default all tables in a database
a.tables = ['table1', 'table2', ...]

# shortlist of tables to exclude  -> default empty
a.without = ['table3', 'table4', ...]

# manual limit to query data -> default 10000 
# not limit -> a.limit = 0 
a.limit = 10000

# run the program
a.run()   

Usage via command line

You can copy example above or create a demo.py file from example using:

python -m mysql2postgresql export_example

You can convert all tables in a MySQL database to PostgreSQL using a command:

python -m mysql2postgresql convert\
    --mysql_host=localhost\
    --mysql_port=3306\
    --mysql_user=root\
    --mysql_password=\
    --mysql_database=db_name\
    --postgresql_host=localhost\
    --postgresql_port=5432\
    --postgresql_user=postgres\
    --postgresql_password=postgres\
    --postgresql_database=database_name

Configuration from standard environment variables is supported reading $MYSQL_HOST, $MYSQL_USER, $MYSQL_PWD, $PGHOST, $PGUSER, $PGPASSWORD.

With above present you only need to add name of the database to convert.

export CONVERT_DATABASE=mydatabase
python -m mysql2postgresql convert

You can copy data only (without a schema) if you already have corresponding Postgres db schema from migrations etc. Turning off schema creation also turns off dropping postgres tables before they get recreated.

export CONVERT_SCHEMA=0

Metadata

Release files for python-mysql2postgresql 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-mysql2postgresql 0.1.2
File Size Uploaded Provenance Actions
python-mysql2postgresql-0.1.2.tar.gz 5.1 kB Without provenance Details for python-mysql2postgresql-0.1.2.tar.gz

Release files / python-mysql2postgresql-0.1.2.tar.gz

Download URL python-mysql2postgresql-0.1.2.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e88e677acb058e989c1d8c1e6de068c72d82dd17c3c1fea9c594ccaade05d1
BLAKE2b-256 checksum
How to use checksums
2529bcdf9fabcd5d2a50d9f7ce8543af1978ab23cdbc225275561f7908c8056b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Security for python-mysql2postgresql 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page