{"id":50730592,"url":"https://github.com/skuong/mysql-replication","last_synced_at":"2026-06-10T08:03:54.663Z","repository":{"id":258907021,"uuid":"875088779","full_name":"skuong/mysql-replication","owner":"skuong","description":"Play around with MySQL replication for new database","archived":false,"fork":false,"pushed_at":"2024-10-21T03:13:52.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-06T09:21:29.238Z","etag":null,"topics":["docker","docker-compose","mysql","mysql8","replication"],"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/skuong.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":"2024-10-19T04:30:04.000Z","updated_at":"2024-10-21T03:13:55.000Z","dependencies_parsed_at":"2024-10-22T05:55:46.218Z","dependency_job_id":null,"html_url":"https://github.com/skuong/mysql-replication","commit_stats":null,"previous_names":["sokhuong-uon/mysql-replication","skuong/mysql-replication"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skuong/mysql-replication","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuong%2Fmysql-replication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuong%2Fmysql-replication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuong%2Fmysql-replication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuong%2Fmysql-replication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skuong","download_url":"https://codeload.github.com/skuong/mysql-replication/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuong%2Fmysql-replication/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34142661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"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":["docker","docker-compose","mysql","mysql8","replication"],"created_at":"2026-06-10T08:03:53.909Z","updated_at":"2026-06-10T08:03:54.658Z","avatar_url":"https://github.com/skuong.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySQL replication for new database\n\n# How to get things running\n## 1. Setup env\n```bash\ncp .env.example .env\n```\nthen setup your variables.\n\n## 2. Generate ssl certificate for mysql servers to connect securely.\n```bash\nchmod +x generate-mysql-certs.sh\n```\n```bash\n./generate-mysql-certs.sh\n```\n\n## 3. Get the stack running\n```bash\ndocker compose up\n```\n\n# How to setup replica\n## 1. Get into `primary_database` container\n```bash\ndocker exec -it primary_database /bin/bash\n```\n\n## 2. Get into `primary_database`'s mysql server\n```bash\nmysql -u root -p\n```\nThen enter the password.\n\n## 3. Check log file and position on source\n```shell\nmysql\u003e show master status\\G;\n*************************** 1. row ***************************\n             File: mysql-bin.000003\n         Position: 157\n     Binlog_Do_DB: chat\n Binlog_Ignore_DB:\nExecuted_Gtid_Set:\n1 row in set (0.00 sec)\n```\nPlease note the file name (in this case `mysql-bin.000003`) and position (in this case `157`).\n\n## 4. Get into `replica1_database` container\nOpen another terminal window or pane and then run\n```bash\ndocker exec -it replica1_database /bin/bash\n```\n\n## 5. Get into `replica1_database`'s mysql server\n```bash\nmysql -u root -p\n```\nThen enter the password.\n\n## 6. Config replica on `replica1_database`\n```sql\nchange replication source to source_host='primary_database', source_log_file='mysql-bin.000003', source_log_pos=157, source_ssl=1, source_ssl_ca='/etc/mysql/certs/ca.pem', source_ssl_cert='/etc/mysql/certs/client-cert.pem', source_ssl_key='/etc/mysql/certs/client-key.pem', get_source_public_key=1;\n```\n\n## 7. Start replication on replica\nDon't forget to change username and password\n```sql\nstart replica user=\"replica_username\" password=\"replica_password\";\n```\n## 8. Check replica status\n```shell\nshow replica status\\G;\n```\n```shell\nmysql\u003e show replica status\\G\n*************************** 1. row ***************************\n             Replica_IO_State: Waiting for source to send event\n                  Source_Host: primary_database\n                  Source_User: replica1\n                  Source_Port: 3306\n                Connect_Retry: 60\n              Source_Log_File: mysql-bin.000003\n          Read_Source_Log_Pos: 157\n               Relay_Log_File: relay-bin.000003\n                Relay_Log_Pos: 326\n        Relay_Source_Log_File: mysql-bin.000003\n           Replica_IO_Running: Yes\n          Replica_SQL_Running: Yes\n              Replicate_Do_DB:\n          Replicate_Ignore_DB:\n           Replicate_Do_Table:\n       Replicate_Ignore_Table:\n      Replicate_Wild_Do_Table:\n  Replicate_Wild_Ignore_Table:\n                   Last_Errno: 0\n                   Last_Error:\n                 Skip_Counter: 0\n          Exec_Source_Log_Pos: 157\n              Relay_Log_Space: 710\n              Until_Condition: None\n               Until_Log_File:\n                Until_Log_Pos: 0\n           Source_SSL_Allowed: Yes\n           Source_SSL_CA_File: /etc/mysql/certs/ca.pem\n           Source_SSL_CA_Path:\n              Source_SSL_Cert: /etc/mysql/certs/client-cert.pem\n            Source_SSL_Cipher:\n               Source_SSL_Key: /etc/mysql/certs/client-key.pem\n        Seconds_Behind_Source: 0\nSource_SSL_Verify_Server_Cert: No\n                Last_IO_Errno: 0\n                Last_IO_Error:\n               Last_SQL_Errno: 0\n               Last_SQL_Error:\n  Replicate_Ignore_Server_Ids:\n             Source_Server_Id: 1\n                  Source_UUID: 28238f79-8dcf-11ef-a015-0242ac120004\n             Source_Info_File: mysql.slave_master_info\n                    SQL_Delay: 0\n          SQL_Remaining_Delay: NULL\n    Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates\n           Source_Retry_Count: 86400\n                  Source_Bind:\n      Last_IO_Error_Timestamp:\n     Last_SQL_Error_Timestamp:\n               Source_SSL_Crl:\n           Source_SSL_Crlpath:\n           Retrieved_Gtid_Set:\n            Executed_Gtid_Set:\n                Auto_Position: 0\n         Replicate_Rewrite_DB:\n                 Channel_Name:\n           Source_TLS_Version:\n       Source_public_key_path:\n        Get_Source_public_key: 1\n            Network_Namespace:\n1 row in set (0.00 sec)\n```\nPlease note if there's any error or else you can continue.\n\n# Playing with replication\n## 1. Create new table in `chat` database in `primary_database` server.\n```sql\nuse chat;\ncreate table message (id int, text varchar(1000));\ncreate table user (id int, bio varchar(1000));\n```\n## 2. Check `chat` database in `replica1_database` server.\n```sql\nuse chat;\nshow tables;\n```\nYou should see both table:\n```shell\n+----------------+\n| Tables_in_chat |\n+----------------+\n| message        |\n| user           |\n+----------------+\n2 rows in set (0.00 sec)\n```\n## Note\nAfter we stopped containers; if we want to play with it again, we need to start replication on replica database again.\n\nLet's say:\n### 1. Stop services\n```bash\ndocker compose down\n```\n### 2. Start services\n```bash\ndocker compose up # or with -d\n```\n### 3. Get into replica database\n```bash\ndocker exec -it replica1_database /bin/bash\n```\n### 4 Get into replica's mysql server\n```bash\nmysql -u root -p\n```\n### 5. Start replication on replica again\nDon't forget to change username and password\n```sql\nstart replica user=\"replica_username\" password=\"replica_password\";\n```\n\n### 6. Check replica status\n```shell\nshow replica status\\G;\n```\n```shell\nmysql\u003e show replica status\\G;\n*************************** 1. row ***************************\n             Replica_IO_State: Waiting for source to send event\n                  Source_Host: primary_database\n                  Source_User: replica1\n                  Source_Port: 3306\n                Connect_Retry: 60\n              Source_Log_File: mysql-bin.000004\n          Read_Source_Log_Pos: 443\n               Relay_Log_File: relay-bin.000005\n                Relay_Log_Pos: 659\n        Relay_Source_Log_File: mysql-bin.000004\n           Replica_IO_Running: Yes\n          Replica_SQL_Running: Yes\n              Replicate_Do_DB:\n          Replicate_Ignore_DB:\n           Replicate_Do_Table:\n       Replicate_Ignore_Table:\n      Replicate_Wild_Do_Table:\n  Replicate_Wild_Ignore_Table:\n                   Last_Errno: 0\n                   Last_Error:\n                 Skip_Counter: 0\n          Exec_Source_Log_Pos: 443\n              Relay_Log_Space: 1032\n              Until_Condition: None\n               Until_Log_File:\n                Until_Log_Pos: 0\n           Source_SSL_Allowed: Yes\n           Source_SSL_CA_File: /etc/mysql/certs/ca.pem\n           Source_SSL_CA_Path:\n              Source_SSL_Cert: /etc/mysql/certs/client-cert.pem\n            Source_SSL_Cipher:\n               Source_SSL_Key: /etc/mysql/certs/client-key.pem\n        Seconds_Behind_Source: 0\nSource_SSL_Verify_Server_Cert: No\n                Last_IO_Errno: 0\n                Last_IO_Error:\n               Last_SQL_Errno: 0\n               Last_SQL_Error:\n  Replicate_Ignore_Server_Ids:\n             Source_Server_Id: 1\n                  Source_UUID: 7832c1a7-8f56-11ef-a214-0242ac120002\n             Source_Info_File: mysql.slave_master_info\n                    SQL_Delay: 0\n          SQL_Remaining_Delay: NULL\n    Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates\n           Source_Retry_Count: 86400\n                  Source_Bind:\n      Last_IO_Error_Timestamp:\n     Last_SQL_Error_Timestamp:\n               Source_SSL_Crl:\n           Source_SSL_Crlpath:\n           Retrieved_Gtid_Set:\n            Executed_Gtid_Set:\n                Auto_Position: 0\n         Replicate_Rewrite_DB:\n                 Channel_Name:\n           Source_TLS_Version:\n       Source_public_key_path:\n        Get_Source_public_key: 1\n            Network_Namespace:\n1 row in set (0.00 sec)\n```\nIf you don't start replication again, you will see error when you run `show replica status\\G;`. So the database won't sync.\n```shell\nmysql\u003e show replica status\\G;\n*************************** 1. row ***************************\n             Replica_IO_State:\n                  Source_Host: primary_database\n                  Source_User:\n                  Source_Port: 3306\n                Connect_Retry: 60\n              Source_Log_File: mysql-bin.000003\n          Read_Source_Log_Pos: 581\n               Relay_Log_File: relay-bin.000002\n                Relay_Log_Pos: 750\n        Relay_Source_Log_File: mysql-bin.000003\n           Replica_IO_Running: No\n          Replica_SQL_Running: Yes\n              Replicate_Do_DB:\n          Replicate_Ignore_DB:\n           Replicate_Do_Table:\n       Replicate_Ignore_Table:\n      Replicate_Wild_Do_Table:\n  Replicate_Wild_Ignore_Table:\n                   Last_Errno: 0\n                   Last_Error:\n                 Skip_Counter: 0\n          Exec_Source_Log_Pos: 581\n              Relay_Log_Space: 930\n              Until_Condition: None\n               Until_Log_File:\n                Until_Log_Pos: 0\n           Source_SSL_Allowed: Yes\n           Source_SSL_CA_File: /etc/mysql/certs/ca.pem\n           Source_SSL_CA_Path:\n              Source_SSL_Cert: /etc/mysql/certs/client-cert.pem\n            Source_SSL_Cipher:\n               Source_SSL_Key: /etc/mysql/certs/client-key.pem\n        Seconds_Behind_Source: NULL\nSource_SSL_Verify_Server_Cert: No\n                Last_IO_Errno: 13117\n                Last_IO_Error: Fatal error: Invalid (empty) username when attempting to connect to the source server. Connection attempt terminated.\n               Last_SQL_Errno: 0\n               Last_SQL_Error:\n  Replicate_Ignore_Server_Ids:\n             Source_Server_Id: 0\n                  Source_UUID: 7832c1a7-8f56-11ef-a214-0242ac120002\n             Source_Info_File: mysql.slave_master_info\n                    SQL_Delay: 0\n          SQL_Remaining_Delay: NULL\n    Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates\n           Source_Retry_Count: 86400\n                  Source_Bind:\n      Last_IO_Error_Timestamp: 241021 02:53:36\n     Last_SQL_Error_Timestamp:\n               Source_SSL_Crl:\n           Source_SSL_Crlpath:\n           Retrieved_Gtid_Set:\n            Executed_Gtid_Set:\n                Auto_Position: 0\n         Replicate_Rewrite_DB:\n                 Channel_Name:\n           Source_TLS_Version:\n       Source_public_key_path:\n        Get_Source_public_key: 1\n            Network_Namespace:\n1 row in set (0.00 sec)\n```\nNote the error `Fatal error: Invalid (empty) username when attempting to connect to the source server. Connection attempt terminated.` **because we don't store username and password in docker volume**.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskuong%2Fmysql-replication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskuong%2Fmysql-replication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskuong%2Fmysql-replication/lists"}