GithubHelp home page GithubHelp logo

pg2mysql's Introduction

pg2mysql

pg2mysql was created to facilitate migrating data from PostgreSQL to MySQL given mostly equivalent schemas.

In PostgreSQL it is common to use the text datatype for character data, which the PostgreSQL documentation describes as having effectively no limit. In MySQL this is not the case, as the datatype with the same name (text) is limited to 65535, and the more common datatype, varchar, is defined with an explicit limit (e.g. varchar(255)).

This means that, given a column with text datatype in PostgreSQL, there must be enough room in the equivalent MySQL column for the data in PostgreSQL to be safely migrated over. This tool can be used to validate the target MySQL schema against a populated PostgreSQL database and, provided the data in the PostgreSQL database is compatible, the migration to move the data from PostgreSQL to MySQL.

Install from source

go get github.com/pivotal-cf/pg2mysql/cmd/pg2mysql

Usage

Create a config:

$ cat > config.yml <<EOF
mysql:
  database: some-dbname
  username: some-user
  password: some-password
  host: 192.168.10.1
  port: 3306

postgresql:
  database: some-dbname
  username: some-user
  password: some-password
  host: 192.168.10.2
  port: 5432
  ssl_mode: disable
EOF

Note: See PostgreSQL documentation for valid SSL mode values.

Run the validator:

$ pg2mysql -c config.yml validate
found incompatible rows in apps with IDs [2]
found incompatible rows in app_usage_events with IDs [9 10 11 12]
found incompatible rows in events with IDs [16 17 18]

If there are any incompatible rows, as in above, they will need to be modified before proceeding with a migration.

Run the migrator:

$ pg2mysql -c config.yml migrate --truncate
inserted 1 records into spaces_developers
inserted 0 records into security_groups_spaces
inserted 0 records into service_bindings
inserted 2 records into droplets
inserted 2 records into organizations
inserted 3 records into lockings
inserted 0 records into service_dashboard_clients
inserted 0 records into route_bindings
...

Note: The --truncate flag will truncate each table prior to copying data over.

Run the verifier after migration to confirm the data has been migrated as expected:

$ pg2mysql -c config.yml verify
Verifying table spaces_developers...OK
Verifying table security_groups_spaces...OK
Verifying table service_bindings...OK
Verifying table droplets...
  FAILED: 1 row missing
  Missing IDs: 1,3,5
Verifying table organizations...OK
Verifying table lockings...OK
Verifying table service_dashboard_clients...OK
Verifying table route_bindings...OK

Verify does an exact comparison (except for timestamps; see Note) of the contents of each row of each table in PostgreSQL to see that a matching row exists in MySQL.

Note: The verify command assumes that the precise PostgreSQL timestamps are truncated when doing the migration over to MySQL. However, it has been found that this behavior is not consistent with all forms of MySQL. Official MySQL rounds the timestamps whereas MariaDB truncates. A PR to intelligently support both would be happily received.

pg2mysql's People

Contributors

krishicks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pg2mysql's Issues

Please configure GITBOT

Pivotal uses GITBOT to synchronize Github issues and pull requests with Pivotal Tracker.
Please add your new repo to the GITBOT config-production.yml in the Gitbot configuration repo.
If you don't have access you can send an ask ticket to the CF admins. We prefer teams to submit their changes via a pull request.

Steps:

  • Fork this repo: cfgitbot-config
  • Add your project to config-production.yml file
  • Submit a PR

If there are any questions, please reach out to [email protected].

Nothing happens when running

This is the command I ran and the output:

bash-3.2$ pg2mysql -c config.yml validate
bash-3.2$ pg2mysql -c config.yml migrate --truncate
Disabling constraints...OK
Enabling constraints...OK
bash-3.2$ pg2mysql -c config.yml verify

After running these commands, no record is transferred to mysql.

'error: failed to validate: failed to get table from destination schema' appears with random tables

go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:05:27 error: failed to validate: failed to get table from destination schema: table 'field_data_field_vertical_banner' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:06:40 error: failed to validate: failed to get table from destination schema: table 'tracker_user' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:06:44 error: failed to validate: failed to get table from destination schema: table 'rules_tags' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:06:47 error: failed to validate: failed to get table from destination schema: table 'field_data_field_duties' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:06:49 error: failed to validate: failed to get table from destination schema: table 'field_data_field_importance' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:06:52 error: failed to validate: failed to get table from destination schema: table 'cache_entity_node' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:07:46 error: failed to validate: failed to get table from destination schema: table 'field_revision_field_gender' not found
go/bin/pg2mysql -c p2m.config.yaml validate
2018/11/23 13:07:49 error: failed to validate: failed to get table from destination schema: table 'custom_breadcrumbs_views' not found...

etc... Can not validate at all.

I got error: this user requires mysql native password authentication

Disabling constraints...[mysql] 2021/12/21 17:31:38 connector.go:95: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
2021/12/21 17:31:38 error: failed migrating: failed to disable constraints: this user requires mysql native password authentication.

error: failed migrating: failed creating prepared statement: Error 1054: Unknown column 'views' in 'field list'

Truncating article_xml_galleys...OK
Migrating article_xml_galleys...OK (0 records inserted)
Truncating books_for_review_settings...OK
Migrating books_for_review_settings...OK (0 records inserted)
Truncating data_object_tombstones...OK
Migrating data_object_tombstones...OK
inserted 14 rows
Truncating notifications...OK
Migrating notifications...OK
inserted 34865 rows
Truncating data_object_tombstone_settings...OK
Migrating data_object_tombstone_settings...OK (0 records inserted)
Truncating published_articles...OK
Enabling constraints...OK
2018/11/26 15:25:07 error: failed migrating: failed creating prepared statement: Error 1054: Unknown column 'views' in 'field list'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.