{"id":19336769,"url":"https://github.com/samrocketman/example-mysql-live-migration","last_synced_at":"2026-05-14T18:32:11.368Z","repository":{"id":145442079,"uuid":"81525832","full_name":"samrocketman/example-mysql-live-migration","owner":"samrocketman","description":"This repository serves as an example of performing a live MySQL database migration.","archived":false,"fork":false,"pushed_at":"2020-10-18T07:11:50.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-24T08:13:35.851Z","etag":null,"topics":["migration","mysql","mysql-backup"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samrocketman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-10T04:20:02.000Z","updated_at":"2022-05-30T17:16:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"93baa33b-c08d-4cfa-851c-75def865e3b3","html_url":"https://github.com/samrocketman/example-mysql-live-migration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/samrocketman/example-mysql-live-migration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocketman%2Fexample-mysql-live-migration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocketman%2Fexample-mysql-live-migration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocketman%2Fexample-mysql-live-migration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocketman%2Fexample-mysql-live-migration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samrocketman","download_url":"https://codeload.github.com/samrocketman/example-mysql-live-migration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocketman%2Fexample-mysql-live-migration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33037809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["migration","mysql","mysql-backup"],"created_at":"2024-11-10T03:12:24.346Z","updated_at":"2026-05-14T18:32:11.339Z","avatar_url":"https://github.com/samrocketman.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example MySQL live migration\n\nThis project is to show an example of how to migrate a MySQL database from one\ninstance to another.  A common scenario is migrating a database from one remote\nmachine to another remote machine.\n\nPrerequisites:\n\n* At least 4 CPU cores.\n* At least 16GB of system memory.\n* Running on a computer which has `bash`, `mysql`, and `mysqldump` commands\n  available (essentially bash and MySQL client only).\n* [Vagrant][vagrant] for provisioning example database servers.  Vagrant depends\n  on [VirtualBox][vbox].\n\nThis example uses dummy MySQL data from [`datacharmer/test_db`][test_db].\n\n# Overview\n\nThe overview of a live MySQL migration process is:\n\n1. On the source and destination database servers create a `datasync` database\n   user which is capable of authenticating remotely with the database.  The user\n   also needs all privileges granted on the database to be migrated.\n2. Set [`mysql-migrate.sh`](mysql-migrate.sh) environment variables for both the\n   source and destination database servers.  This is required to properly\n   connect and authenticate with the source and destination database servers.\n3. Execute `mysql-migrate.sh`.\n\n# mysql-migrate.sh environment variables\n\n`mysql-migrate.sh` script can have several environment variables set to\ncustomize its behavior.  The default variables are to simplify running examples\nin this repository.\n\nSource database server vars:\n\n* `SRC_DB_HOST` - hostname (default: `127.0.0.1`)\n* `SRC_DB_PORT` - port of the MySQL service (default: `3333`)\n* `SRC_DB_USER` - username of database user (default: `datasync`)\n* `SRC_DB_PASSWORD` - password of database user (default: `syncpw`)\n* `SRC_DB_DATABASE` - (default: `employees`)\n\nDestination database server vars:\n\n* `DST_DB_HOST` - hostname (default: `127.0.0.1`)\n* `DST_DB_PORT` - port of the MySQL service (default: `3334`)\n* `DST_DB_USER` - username of database user (default: `datasync`)\n* `DST_DB_PASSWORD` - password of database user (default: `syncpw`)\n\n\u003e **WARNING:** `SRC_DB_PORT` and `DST_DB_PORT` are not default to 3306 which is\n\u003e the typical MySQL port.  Be aware of this.\n\n# Run the example migration\n\nSet up your database servers.  Execute:\n\n    vagrant up\n\n`vagrant up` will provision two database servers (`src_db` and `dst_db`) based\non the [`Vagrantfile`](Vagrantfile).  This will set up both database servers\nwith a MySQL service and creating the `datasync` database user on both servers.\nIt will also populate the `src_db` service with [dummy MySQL data][test_db] for\nrunning the example migration.\n\nPerform the migration.  Execute:\n\n    bash mysql-migrate.sh\n\nThe above command will dump from the source database and import the dump to the\ndestination database.\n\n\u003e **Tip:** Before migrating, inspect both the source and destination database\n\u003e servers.\n\n# Other helpful commands\n\nLog into the source database server.\n\n    vagrant ssh src_db\n\nLog into the destination database server.\n\n    vagrant ssh dst_db\n\nYou can log into the database directly from the database servers if you run\n`mysql` as the `root` user.\n\n    sudo mysql\n\nAlternatively, connect to the destination database remotely using a local\n`mysql` command.\n\n    mysql -h 127.0.0.1 -P 3334 -u datasync -psyncpw\n\n# Notes\n\n* In the [`Vagrantfile`](Vagrantfile), the `datasync` user is allowed to\n  authenticate from any remote machine.  This is not a recommended practice.\n  Instead, limit the `datasync` user to authenticate only from known networks or\n  computers in an active database environment.\n* Don't use any example passwords in this repository to create accounts on\n  active database servers.\n* To improve performance of the destination database import, `/etc/my.cnf` can\n  be edited to increase [`innodb_write_io_threads=64`][innodb_write_io] of the\n  destination database server.\n* If you encounter `mysql` timeouts because the data being exported is too large\n  in a single statement, then add `--skip-extended-insert` to the `mysqldump`\n  command.  Without the option migration time increases from 30 seconds to about\n  20 minutes.  However, it is much more reliable.  I've encountered this need in\n  databases for document management systems.\n\n[test_db]: https://github.com/datacharmer/test_db\n[vagrant]: https://www.vagrantup.com/\n[vbox]: https://www.virtualbox.org/\n[innodb_write_io]: https://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_write_io_threads\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamrocketman%2Fexample-mysql-live-migration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamrocketman%2Fexample-mysql-live-migration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamrocketman%2Fexample-mysql-live-migration/lists"}