MySQL database master-slave copy add nth from library

Source: Internet
Author: User

Add MySQL from library

MySQL Master slave replication server 1 master 1 from, now to add a MySQL from the server, require the main library cannot stop the service, previously due to not the server on the line, you can execute the flush tables with read lock statement on the primary server (lock table, read-only), All the tables can only read and write, and then copy the main library data to the new from the library server, and maintain data consistency, now only one way, thinking new from the Library 2 copy old from the library 1 data!



Operations from library 1

Mysql> show Slave status\g;
1. Row ***************************
Slave_io_state:waiting for Master to send event
master_host:192.168.2.115
Master_user:rep1
master_port:3306
Connect_retry:60
master_log_file:mysql-bin.000001
read_master_log_pos:19725129
relay_log_file:web-relay-bin.000002
relay_log_pos:283
relay_master_log_file:mysql-bin.000001
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:19725129
relay_log_space:454
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:8bb53f82-bc15-11e6-9d52-000c2974e60c
Master_info_file:/usr/local/mysql/data/master.info
sql_delay:0
Sql_remaining_delay:null
Slave_sql_running_state:slave have read all relay log; Waiting for the SLA ve I/O Thread to update it
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
1 row in Set (0.00 sec)

ERROR:
No query specified

Package data transfer to from library 2

Cd/usr/local/mysql/data

TAR-ZCVF zabbix.tar.gz zabbix/

SCP zabbix.tar.gz [email protected] (from library 2ip):/usr/local/mysql/daba/



Operations from Library 2

Changing Server-id is not the same as from library 1 and the main library

Place the transferred data in the specified library

TAR-ZXVF zabbix.tar.gz

MySQL > Change master to master_host= ' 192.168.2.115 ', master_user= ' rep1 ', master_password= ' password ', Master_log_ File= ' mysql-bin.000001 ', master_log_pos=19725129;

mysql > Starat slave;

MySQL > show slave status\g

Mysql> show Slave status\g;
1. Row ***************************
Slave_io_state:waiting for Master to send event
master_host:192.168.2.115
Master_user:rep1
master_port:3306
Connect_retry:60
master_log_file:mysql-bin.000001
read_master_log_pos:19725129
relay_log_file:web-relay-bin.000002
relay_log_pos:283
relay_master_log_file:mysql-bin.000001
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:19725129
relay_log_space:454
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:8bb53f82-bc15-11e6-9d52-000c2974e60c
Master_info_file:/usr/local/mysql/data/master.info
sql_delay:0
Sql_remaining_delay:null
Slave_sql_running_state:slave have read all relay log; Waiting for the SLA ve I/O Thread to update it
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
1 row in Set (0.00 sec)

ERROR:
No query specified



Now it's okay.


MySQL database master-slave copy add nth from library

Related Article

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.