NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
database-specialist-db-1 database-specialist-db "docker-entrypoint.s…" db 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp
database-specialist-rep_p-1 database-specialist-rep_p "docker-entrypoint.s…" rep_p 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:13306->3306/tcp
database-specialist-rep_s-1 database-specialist-rep_s "docker-entrypoint.s…" rep_s 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:23306->3306/tcp
プライマリーは 13306, セカンダリーは23306でアクセスができる。
プライマリーでダンプを取得する
1
docker compose exec rep_p bash
MySQLにrootでログインをする。
1
mysql -u root -proot
レプリケーション用のユーザを作成する。
1
2
CREATEUSER'repl'@'%' IDENTIFIED WITH mysql_native_password BY'password';
GRANT REPLICATION SLAVE ON*.*TO'repl'@'%';
1
2
3
4
5
mysql> CREATE USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
ON *.* TO 'repl'@'%';Query OK, 0 rows affected (0.03 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
Query OK, 0 rows affected (0.03 sec)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a31c3dce4e0 database-specialist-rep_p "docker-entrypoint.s…"6 minutes ago Up 6 minutes 33060/tcp, 0.0.0.0:13306->3306/tcp database-specialist-rep_p-1
09c947c71829 database-specialist-db "docker-entrypoint.s…"6 minutes ago Up 6 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp database-specialist-db-1
b1c624d6d0c4 database-specialist-rep_s "docker-entrypoint.s…"6 minutes ago Up 6 minutes 33060/tcp, 0.0.0.0:23306->3306/tcp database-specialist-rep_s-1
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to source
Master_Host: rep_p
Master_User: repl
Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 844 Relay_Log_File: b1c624d6d0c4-relay-bin.000001
Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0 Last_Error:
Skip_Counter: 0 Exec_Master_Log_Pos: 844 Relay_Log_Space: 157 Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0 Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2061 Last_IO_Error: Error connecting to source 'repl@rep_p:3306'. This was attempt 1/10, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
Last_SQL_Errno: 0 Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0 Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0 SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 10 Master_Bind:
Last_IO_Error_Timestamp: 230826 05:03:47
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0 Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0 Network_Namespace:
1 row in set, 1 warning (0.00 sec)ERROR:
No query specified
動作検証
トラブルシューティング
レプリケーション後に下記のようなエラーが出る。
1
mysql> show slave status \G;
1
2
Last_IO_Errno: 2061Last_IO_Error: Error connecting to source 'repl@rep_p:3306'. This was attempt 8/10, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.