Master-slave Replication database note time to synchronize:
Ntpdate 172.18.0.1 #以本局域网的某一主机作为时钟服务器
Primary server:
VIM/ETC/MY.CNF.D/SERVER.CNF [Server] Skip_name_resolve=on//Ignore name Resolution Innodb_file_per_table=on//each storage table consumes a separate file serv er_id = 1//service ID, must exist Log_bin = msater-bin//binary log, this is relative path, relative to/var/lib/mysql
Start the Mariadb.service service
GRANT REPLICATION slave,replication CLIENT on * * to ' repluser ' @ ' 192.168.1.% ' identified by ' CentOS '; The user rights required to authorize replication from the service//replication SLAVE are often used to establish replication,//replication client is not available for replication, and when this permission is available, only more can be used such as "SHOW SLAVE STATUS", " SHOW MASTER STATUS "command. FLUSH privileges;//write to disk show MASTER status;//view binary log status
From the server:
VIM/ETC/MY.CNF.D/SERVER.CNF [Server] skip_name_resolve = on innodb_file_per_table = on server_id = 2 Relay_log = relay-log//relay logs are used to hold binary content read from the primary server Read_only=on//read-only from the server can not write
Start the Mariadb.service service
Change MASTER to master_host= ' 192.168.1.101 ', master_user= ' repluser ', master_password= ' CentOS ', master_log_file= ' Master-log.000003 ', master_log_pos=495;//connect to the primary server's authorized account and start copying the start SLAVE from the specified binary log location io_thread,sql_thread;// Open the IO and SQL processes from the node, the former is the IO operation from the primary server, the latter is the SQL operation from the server itself show SLAVE status\g;//last view from the service state, each parameter can be explained literally, no longer repeat
Test:
At this point, a database or table is created on the primary server, and then viewed from the server, it is possible to see the newly created library or table, although nothing is created from itself;
This completes the master-slave copy
This article from "A_pan" blog, declined reprint!
MySQL database master-slave replication