MySQL database master-slave replication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.