Mysql5.7.13 Master-Slave Synchronization (replication) configuration

Source: Internet
Author: User
Tags mysql client mysql version

Master-Slave synchronization is a very important configuration of the distributed MySQL database, I now complete the master-slave configuration on the virtual machine, the system is Centeros6.5,mysql version is 5.7.13

The IP of the primary server is the IP of the 192.168.19.139 secondary server is 192.168.19.142

1. Primary server Configuration

(1) Modify MY.CNF (note using root)

1vim/etc/my.cnf2 3 4Sql_mode=No_engine_substitution,strict_trans_tables5log-bin=mysqlbin-Log6Server_id=17basedir=/home/MySQL8User=MySQL9datadir=/home/mysql/DataTenport=3306 Oneinnodb_flush_log_at_trx_commit=1 Async_binlog=1 -Log-slave-updates

(2) Go to the bin in the MySQL installation directory and start MySQL

1 cd/home/mysql/bin 2 ./mysqld

(3) Re-open the MySQL client, into the MySQL installation directory of the bin, authorized Vice-server master-slave replication, with mysqld The advantage is that you can view the error.

1 ./mysql-uroot-P 2 mysql> grant replication Slave on * * to [email protected]192. 168. 19.142 identified by '123';

(4) Show primary server status

1 mysql> show master status; 2 +---------------------+----------+--------------+------------------+-------------------+3 | File                | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set | 4 +---------------------+----------+--------------+------------------+-------------------+5 | Mysqlbin-log. 000019 |     1290 | | | |                   6 +---------------------+----------+--------------+------------------+-------------------+

2. Sub-server Configuration

(1) Modify MY.CNF (note using root)

  1  vim/etc/my.cnf   2   3  sql_mode=no_engine_substitution, strict_trans_table   4  user=mysql   server_id = 2   replicate-do -db = sbfxd   7  master-info-file = Master.info   8  relay-log = Relay-relay-bin  Span style= "color: #008080;" > 9  Relay-log-index = Relay-relay-bin.index  10  relay-log-info-file=relay-relay-log.info 

(2) Go to the bin in the MySQL installation directory and start MySQL

1 cd/home/mysql/bin 2./mysqld

(3) Re-open the MySQL client, go to the bin in the MySQL installation directory, set the Slave property and start the service

1 ./mysql-uroot-P2 mysql> change master to master_host='192.168.19.139  '3306, master_log_file='mysqlbin-log.000019'1290 , master_bind='; 3 mysql> start slave;

(4) Display the status of the secondary server

1 show slave status \g;2 3Slave_io_state:waiting forMaster to sendEvent4Master_host:192.168.19.1395 master_user:test6Master_port:33067Connect_retry: -8Master_log_file:mysqlbin-log.0000199Read_master_log_pos:1290TenRelay_log_file:relay-relay-bin.000002 OneRelay_log_pos:323 ARelay_master_log_file:mysqlbin-log.000019 - Slave_io_running:yes - Slave_sql_running:yes the Replicate_do_db:sbfxd - replicate_ignore_db: - replicate_do_table: - replicate_ignore_table: + replicate_wild_do_table: - replicate_wild_ignore_table: +Last_errno:0 A Last_error: atSkip_counter:0 -Exec_master_log_pos:1290 -Relay_log_space:530 - Until_condition:none - Until_log_file: -Until_log_pos:0 in Master_ssl_allowed:no - Master_ssl_ca_file: to Master_ssl_ca_path: + Master_ssl_cert: - Master_ssl_cipher: the Master_ssl_key: *Seconds_behind_master:0 $ Master_ssl_verify_server_cert:noPanax NotoginsengLast_io_errno:0 - Last_io_error: theLast_sql_errno:0 + Last_sql_error: A Replicate_ignore_server_ids: theMASTER_SERVER_ID:1 +Master_uuid:05408021-5ab2-11e6-869b-000C293990C1 -Master_info_file:/home/mysql/data/Master.info $Sql_delay:0 $ Sql_remaining_delay:null -Slave_sql_running_state:slave have read all relay log; Waiting forMore Updates -Master_retry_count:86400 the Master_bind: - Last_io_error_timestamp:Wuyi Last_sql_error_timestamp: the MASTER_SSL_CRL: - Master_ssl_crlpath: Wu Retrieved_gtid_set: - Executed_gtid_set: AboutAuto_position:0 $ replicate_rewrite_db: - Channel_name: -Master_tls_version:

There are two yes means slave can run.

3. Precautions:

(1) The landlord of the virtual machine is generated by cloning, so do not need to backup MySQL, and then restore on the secondary server, this step for the database is extremely important, otherwise the following error will appear:

1  .- ,-17t03: One: -.579193Z5[ERROR] Slave SQL forChannel"': Error Executing rowEvent:'Table'Sbfxd.sbtable'doesn'T exist', error_code:11462  .- ,-17t03: One: -.584268Z5[Warning] Slave:table'sbfxd.sbtable'doesn't exist error_code:1146

(2) If the properties of the primary server are incorrectly configured to require stop slave, then start slave

Mysql5.7.13 Master-Slave Synchronization (replication) configuration

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.