mysql> show master status \G *************************** 1. row *************************** File: mysql-bin.000001 Position: 595 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec)
Configure Slave
1 2 3 4 5 6 7 8 9
$ vi /etc/my.cnf
[mysqld] server-id=2 relay_log=relay-log skip-slave-start **/ useful to make any checks before starting the slave (this way, slave must be started manually after each mysql restart)
$ systemctl restart mysqld
**Option:**恢复数据
1
$ mysql -u root -p < /path/to/backupdir/full_backup-$TIMESTAMP.sql
1 2 3 4 5
从备份文件中获取Master的日志位置信息。
$ head -n 50 /path/to/backupdir/full_backup-$TIMESTAMP.sql|grep "CHANGE MASTER TO" OR Master> show master status \G
slavel> show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.77.17 Master_User: replicator Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 595 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 320 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes ......
If the Slave_IO_State= connecting … then make sure that the slave user information is set correctly and there is no firewall restrictions between the two servers (master and slave) this could be checked by connecting to the master’s MySQL from the salve server by the replication user (in this example, slave_user_name).
If both Slave_IO_Running and Slave_SQL_Running = Yes, then the replication had been set up correctly.
If the Slave_SQL_Running = No, check the value of Last_SQL_Error for more details about the SQL error.
If you know that error and you want to ignore it, you can execute “SET GLOBAL sql_slave_skip_counter = 1;” on the slave and then start the slave again “START SLAVE;”.
To restrict all normal users from changing data on the slave - which might break the replication - the option “read-only” should be added in the slave’s my.cnf file.
the server option “server-id” must be unique among all servers inside the replication (masters and slaves).
If your database size is big (100GB or so) Xtrabackup tool could be used instead of mysqldump - when preparing the master snapshot - for faster backup and restore operations.