Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Principle of mysql master-slave replication

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment:

3306 main library

3307 from the library

1 set the server-id value and enable the binlog function parameters

Edit the configuration file / data/3306/my.cnf for mysql

[mysqld]

Server-id = 6-sever-id of each machine or instance used for synchronization cannot be the same

Log_bin = / data/3306/mysql-bin-can be omitted

Restart the service

/ data/3306/mysql restart

Check idea one

[root@db02 data] # egrep "log_bin | server-id" 330*/my.cnf

3306/my.cnf:log_bin = / data/3306/mysql-bin

3306/my.cnf:server-id = 6

3307/my.cnf:server-id = 7

Check idea 2:

Check idea 2:

Login:

[root@db02 data] # mysql-S / data/3306/mysql.sock

View variables:

Mysql > show variables like 'log_bin%'

+-+

| | Variable_name | Value |

+-+

| | log_bin | ON |

| | log_bin_basename | / data/3306/mysql-bin |

| | log_bin_index | / data/3306/mysql-bin.index |

| | log_bin_trust_function_creators | OFF |

| | log_bin_use_v1_row_events | OFF |

+-+

5 rows in set (0.00 sec)

2 authorizing the establishment of an account [main database]

Grant replication slave on *. * to 'rep'@'172.16.1.%' identified by' oldboy123'

Flush privileges

3 lock table export data

Mysql > flush table with read lock

Query OK, 0 rows affected (0.00 sec)

View location:

Mysql > show master status

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | |

+-+

| | mysql-bin.000001 | 405 |

+-+

1 row in set (0.00 sec)

New window backup:

Mysqldump-uroot-paired oldboy123'-S / data/3306/mysql.sock-A-B | gzip > / server/backup/mysql_bak.$ (date +% F) .sql.gz

Unlock the original window:

Mysql > show master status

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | |

+-+

| | mysql-bin.000001 | 405 |

+-+

1 row in set (0.00 sec)

Mysql > unlock tables

Query OK, 0 rows affected (0.01 sec)

The following command replaces all the steps of 3

Mysqldump-uroot-paired oldboy 123'-master-data=2-S / data/3306/mysql.sock-A-B

4. Import data into the slave library

[root@db02 backup] # mysql-S / data/3307/mysql.sock

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report