Mysql master-slave replication hints
- tested on mysql8
port listening
- don't forget to adjust bind-address option.on master side at least E.g.
bind-address = 0.0.0.0
Settings of a master
Master configuration
[mysqld] ... server-id = 1 report_host = master1 log_bin = /var/lib/mysql/mariadb-bin.log log_bin_index = /var/lib/mysql/mariadb-bin.index relay_log = /var/lib/mysql/relay-bin relay_log_index = /var/lib/mysql/relay-bin.index expire_logs_days = 10 auto_increment_increment = 1 slave-skip-errors=all
Master create replication user + privileges
mysql> create user 'replicationu'@'%' identified by 'test'; mysql> grant replication slave on *.* to 'replicationu'@'%';
Master get master status
(will be used in the Slave setting):
mysql> flush tables with read lock; mysql> show master status; +--------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +--------------------+----------+--------------+------------------+ | mariadb-bin.000004 | 157 | | | +--------------------+----------+--------------+------------------+ 1 row in set (0.104 sec)
Backup data and copy mysqldump to slave
mysqldump -u root voipmonitor > /tmp/voipmonitor.sql scp /tmp/voipmonitor.sql dest_ip://tmp
Unlock the tables on master
mysql> UNLOCK TABLES;
Settings on the slave
Slave configuration
[mysqld] ... server-id = 2 report_host = slave log_bin = /var/lib/mysql/mariadb-bin.log log_bin_index = /var/lib/mysql/mariadb-bin.index relay_log = /var/lib/mysql/relay-bin relay_log_index = /var/lib/mysql/relay-bin.index expire_logs_days = 10 slave-skip-errors=all
Restore mysqldump on slave
mysql> CREATE DATABASE voipmonitor; mysql voipmonitor < /tmp/voipmonitor.sql
Slave settings
(use master status from server 1):
mysql> stop replica; mysql> CHANGE REPLICATION SOURCE TO SOURCE_HOST='192.168.45.58', SOURCE_USER='replication', SOURCE_PASSWORD='replicationpass', SOURCE_LOG_FILE='mariadb-bin.000004', SOURCE_LOG_POS=157; mysql> start replica;
Slave's replication status
mysql> show replica status\G
*************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 192.168.45.58 Source_User: replication Source_Port: 3306 Connect_Retry: 60 Source_Log_File: mariadb-bin.000005 Read_Source_Log_Pos: 157 Relay_Log_File: relay-bin.000007 Relay_Log_Pos: 377 Relay_Source_Log_File: mariadb-bin.000005 Replica_IO_Running: Yes Replica_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_Source_Log_Pos: 157 Relay_Log_Space: 752 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Source_SSL_Allowed: No Source_SSL_CA_File: Source_SSL_CA_Path: Source_SSL_Cert: Source_SSL_Cipher: Source_SSL_Key: Seconds_Behind_Source: 0 Source_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Source_Server_Id: 1 Source_UUID: 3672683e-9d7e-11ed-b84f-000c2907b34b Source_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates Source_Retry_Count: 86400 Source_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Source_SSL_Crl: Source_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Source_TLS_Version: Source_public_key_path: Get_Source_public_key: 0 Network_Namespace: 1 row in set (0.00 sec)