Replication, Replication is the underlying middleware foundation, MHA, mycat such as high availability are dependent replication principle
Examples of master slave from the master instance
Category: Default asynchronous replication, semi-synchronous replication after version 5.5, the new 5.6 version GTID copy, multi-source copy version 5.7, semi-synchronous replication based on parallel replication group submitted and enhancements
Copy: 1 traditional methods: log-based replication binlog 2.GTID: things based replication
binlog can have different formats: based on sentence, based on the line data, the mixed (line data replication is the default)
The following structures under conventional asynchronous replication
Necessary conditions: server_id between master and slave different; the main library open binlog, easy to open architecture also recommended extension from the library
First edit my.cnf open binlog and set server_id
mysql> show variables like '%log_bin%';
+---------------------------------+---------------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------------+
| log_bin | ON |
| log_bin_basename | /usr/local/mysql/data/mysql-bin |
| log_bin_index | /usr/local/mysql/data/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+---------------------------------------+
6 rows in set (0.00 sec)
mysql> ^DBye
[root@localhost ~]$ cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
log_bin=mysql-bin
server_id=1
[root@localhost ~]$
Then create a master copy of the user, before the experiment has been created scott user, use this, and then Empowerment (because users can save passwords in clear text in master.info slave of fact should be established so that only one copy of individual rights)
mysql> grant replication slave on *.* to 'scott'@'%';
Query OK, 0 rows affected (0.00 sec)
Table locking stop modification
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 556 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> drop table tmp;
ERROR 122
Then the main library passed a full backup backup database data directory can be directly packaged in the past (innodb not recommended) or directly mysqldump
[root@localhost ~]$ mysqldump --all-databases -uroot -pmysql --master-data > dbdump.db
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]$ ls
dbdump.db
[root@localhost ~]$ scp dbdump.db 192.0.1.11:~
The authenticity of host '192.0.1.11 (192.0.1.11)' can't be established.
ECDSA key fingerprint is SHA256:pmk8Q9EnT+TugRZ5rb2bc0GP20ZV3LkeuXP/Jrw5tbs.
ECDSA key fingerprint is MD5:13:d1:4a:14:3a:4d:fd:33:56:15:f9:1f:2f:44:87:2c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.0.1.11' (ECDSA) to the list of known hosts.
[email protected]'s password:
dbdump.db
Application library is then prepared
mysql> source dbdump.db
Configuration information from the master database repository
mysql> change master to
-> master_host='192.0.1.10',
-> master_user='scott',
-> master_password='tiger',
-> master_port=3306,
-> master_log_file='mysql-bin.000003',
-> master_log_pos=556;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql>
Turn sync on
mysql> start slave ;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.0.1.10
Master_User: scott
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 556
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
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: 556
Relay_Log_Space: 531
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 531fa6d1-627f-11e9-8dc7-000c297887a1
Master_Info_File: /data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
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:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
Release the lock main library
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
Well under verification, insert a record into the main library, the library immediately from there