Master-slave Data Synchronization for Mysql servers

Source: Internet
Author: User
Tags localhost mysql

Example of Master-Slave Data Synchronization for Mysql Server: How can I synchronize data from A Master server to A Slave server by using server A as the Master server (Master) and server B1 and server B2 as the Slave server (Slave, let's take a look. Www.2cto.com Master: modify the configuration file:/etc/my. cnf [root @ localhost ~] # Vim/etc/my. cnf [mysqld] log-bin = binloglog-bin-index = binlog. indexsync_binlog = 0server_id = 1 restart mysql: www.2cto.com [root @ localhost ~] #/Etc/init. d/mysqld restart stop MySQL: [OK] Start MySQL: [OK] [root @ localhost ~] # Slave1: modify the configuration file:/etc/my. cnf [root @ localhost ~] # Vim/etc/my. cnf [mysqld] server_id = 2relay_log =/var/lib/mysql/mysql-relay-binrelay_log_index =/var/lib/mysql/mysql-relay-bin.index restart mysql: [root @ localhost ~] #/Etc/init. d/mysqld restart stop MySQL: [OK] Start MySQL: [OK] [root @ localhost ~] # Slave2: modify the configuration file:/etc/my. cnf [root @ localhost ~] # Vim/etc/my. cnf [mysqld] server_id = 3relay_log =/var/lib/mysql/mysql-relay-binrelay_log_index =/var/lib/mysql/mysql-relay-bin.index restart mysql: [root @ localhost ~] #/Etc/init. d/mysqld restart stop MySQL: [OK] www.2cto.com start MySQL: [OK] [root @ localhost ~] # Master: [root @ localhost ~] # MysqlWelcome to the MySQL monitor. commands end with; or \ g. your MySQL connection id is 2 Server version: 5.0.77-log Source distribution Type 'help; 'or' \ H' for help. type '\ C' to clear the buffer. mysql> GRANT replication slave ON *. * TO 'AB' @ '%' identified by '000000'; Query OK, 0 rows affected (123 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) slave1: [root @ localhost ~] # Cd/var/lib/mysql/[root @ localhost mysql] # lsibdata1 ib_logfile0 ib_logfile1 mysql. sock test [root @ localhost mysql] # rm-rf * [root @ localhost mysql] # ls [root @ localhost mysql] #/etc/init. d/mysqld restart Master: [root @ localhost ~] # Mysqldump-A-x>/tmp/full. SQL [root @ localhost ~] # Scp/tmp/full. SQL root@192.168.18.117:/tmp/The authenticity of host' 192. 168.18.117 (192.168.18.117) 'Can't be established. RSA key fingerprint is 1f: ce: 39: 33: 61: f5: 7d: f8: 0b: 89: c7: d8: 06: 46: 79: 1f. are you sure you want to continue connecting (yes/no )? YesWarning: Permanently added '192. 168.18.117 '(RSA) to the list of known hosts.root@192.168.18.117's password: full. SQL 192 100% 1039 MB 4.8 MB/s [root @ localhost ~] # Slave1: [root @ localhost mysql] # mysql </tmp/full. SQL Master: mysql> flush tables with read lock; mysql> show master status; + metric + ---------- + -------------- + usage + | File | Position | usage | + --------------- + ---------- + -------------- + usage + | binlog.000003 | 365 | + metric + ---------- + -------------- + ---------------- + 1 row in set (0.03 sec) mysql> unlock tables; Query OK, 0 rows affected (0.03 sec) Slave1: mysql> change master to master_host = '2017. 168.18.107 ', master_port = 3306, master_user =' AB ', master_password = '000000', master_log_file = 'binlog. 000003 ', master_log_pos = 365; Query OK, 0 rows affected (0.06 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave status \ GSlave_IO_Running: yesSlave_ SQL _Running: Ye SSlave1: [root @ localhost ~] # Mysqldump-A-x>/tmp/mysql. SQL [root @ localhost ~] # Scp/tmp/mysql. SQL root@192.168.18.127:/tmp/The authenticity of host' 192. 168.18.127 (192.168.18.127) 'Can't be established. RSA key fingerprint is f7: a5: 9e: 2f: 86: 57: a5: 17: f4: ad: 2b: 3a: a8: 55: 0f: 76.Are you sure you want to continue connecting (yes/no )? YesWarning: Permanently added '2017. 168.18.127 '(RSA) to the list of known hosts.root@192.168.18.127's password: mysql. SQL 100% 1039 MB 20.8 MB/s [root @ localhost mysql] # Slave2: [root @ localhost mysql] # mysql </tmp/mysql. sqlMaster: mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status; + metric + ---------- + -------------- + usage + | File | Position | usage | + --------------- + ---------- + -------------- + usage + | binlog.000003 | 365 | + metric + ---------- + -------------- + ------------------ + 1 row in set (0.00 sec) mysql> unlock tables; Query OK, 0 rows affected (0.00 sec) Slave2: mysql> change master to master_host = '2017. 168.18.107 ', master_port = 3306, master_user =' AB ', master_password = '000000', master_log_file = 'binlog. 000003 ', master_log_pos = 365; Query OK, 0 rows affected (0.05 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) test: mysql> show slave status \ G in the output data, the following statement is yes success Slave_IO_Running: YesSlave_ SQL _Running: Yes
 

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.