{"id":18029805,"url":"https://github.com/ajaxray/mysql8-replication","last_synced_at":"2025-05-12T16:41:12.873Z","repository":{"id":222952121,"uuid":"758665808","full_name":"ajaxray/mysql8-replication","owner":"ajaxray","description":"Testing MySQL 8 GTID Based Master-Slave Replication","archived":false,"fork":false,"pushed_at":"2024-02-19T16:06:42.000Z","size":963,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-18T00:43:20.540Z","etag":null,"topics":["docker","docker-compose","mysql","replication"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajaxray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-02-16T20:00:12.000Z","updated_at":"2024-11-20T16:16:08.000Z","dependencies_parsed_at":"2024-02-17T08:42:43.894Z","dependency_job_id":null,"html_url":"https://github.com/ajaxray/mysql8-replication","commit_stats":null,"previous_names":["ajaxray/mysql8-replication"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fmysql8-replication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fmysql8-replication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fmysql8-replication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fmysql8-replication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajaxray","download_url":"https://codeload.github.com/ajaxray/mysql8-replication/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238065159,"owners_count":19410588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["docker","docker-compose","mysql","replication"],"created_at":"2024-10-30T09:11:33.395Z","updated_at":"2025-02-10T05:41:56.308Z","avatar_url":"https://github.com/ajaxray.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Testing MySQL 8 GTID Based Replication \n\nThe docker-compose configuration will create 2 containers of MySQL 8 server. \nThey are configured properly for testing MySQL 8 GTID based Master-Slave replication.\n\nFollowing the steps listed below, you can configure and experience replication feature in 5 minutes!\n\n\u003ca href=\"./screenshot.png\" target=\"_blank\"\u003e\n    \u003cimg src=\"./screenshot.png\" alt=\"MySQL GTID Master-Slave Replication\" width=\"800px\"\u003e\n\u003c/a\u003e\n\n---\n\n\u003e ⚠️ **Assumptions**:  \n\u003e - Assuming you have both Docker Engine and Docker Compose installed and configured. \n\u003e - Assuming you have a basic understanding of Docker and MySQL. \n\n## Step 1: Start the containers\n\nClone the repo, enter into directory, and start the containers.\n```shell\ngit clone git@github.com:ajaxray/mysql8-replication.git\ncd mysql8-replication\ndocker-compose up --build -d\n```\n\n## Step 2: Create a user for replication\n\nLog into the master databases\n\n```shell\ndocker-compose exec master_db mysql -uroot -proot\n```\n\nAnd create a user with replication permission\n\n```sql\nCREATE USER 'replication_user'@'192.168.%' IDENTIFIED WITH mysql_native_password BY '123123';\nGRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'192.168.%';\nFLUSH PRIVILEGES;\n```\n\n## Step 3: Start replication from the slave\n\nLog into the slave databases (from a different shell window)\n\n```shell\ndocker-compose exec slave_db mysql -uroot -proot\n```\n\nThen, configure the source and start replication.\n\n```sql\nCHANGE REPLICATION SOURCE TO SOURCE_HOST='master_db', SOURCE_USER='replication_user', SOURCE_PASSWORD='123123', SOURCE_AUTO_POSITION=1;\nSTART REPLICA;\n```\n\n## Step 4: Verify\n\nAdd some database, tables, records in the master_db and check if it's available in the slave_db. \nYou may use `sandbox` database and `test_table` table that was prepared automatically \nat the time of starting the containers. For example - \n```sql\nUSE sandbox;\nINSERT INTO test_table VALUES(1, 'name', 'ajaxray');\nSELECT * FROM test_table;\n```\nAnd then, try selecting the record from the slave_db. (Don't insert from slave!)\n\nIf you don't see the changes are replicating as expected, run the following SQL command in slave_db.\n```sql\nSHOW SLAVE STATUS\\G\n```\nAnd, check the following information for any potential error:\n\n- Last_IO_Errno\n- Last_IO_Error\n- Last_SQL_Errno\n- Last_SQL_Error\n\n## Step 5: Cleanup\n\nExit from both of the containers using `exit`.  \nThen execute the `cleanup.sh` to stop the containers and remove all data and log files.\n\n```shell\nchmod +x ./cleanup.sh \u0026\u0026 ./cleanup.sh\n```\n\nThis cleanup script will remove all the data and log files along with the containers. \nIf you want to keep current data and just to stop the containers, you can just use\n```shell\ndocker-compose down\n```\n\n## Contribution guide\n\nFeel free to submit an issue if you face any error. \nSuggestions/PRs are most welcome! 🤗\n\n---\n\u003e \"This is the Book about which there is no doubt, a guidance for those conscious of Allah\" - [Al-Quran](http://quran.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxray%2Fmysql8-replication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajaxray%2Fmysql8-replication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxray%2Fmysql8-replication/lists"}