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

Mysql Multi-master and one Slave data backup method tutorial

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

Share

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

Overview

Operations on any one database are automatically applied to another database, always keeping the data in the two databases consistent.

This has the following advantages:

Can make disaster preparedness, one of which can be switched to the other if it is broken. You can do load balancing and apportion the request to any one of them to improve the throughput of the website. For remote hot backup, it is especially suitable for disaster preparedness.

The way of MySQL master-slave replication

1 when any database operated by the Master database, the operation record is written to the biglog log file

2 the Slave database obtains the log file of the main database through the network, writes it to the local log system, and then completes the database events in the database one by one.

3 Slave redoes the events in the relay log, reflecting the changes on Master into its own database, so the data on both sides is exactly the same.

Environment

Operating system: CentOS

MySQL version: mysql-5.6.26 (the master and slave database versions must be the same)

Master1 configuration

1 enable binlog log function

Vim / etc/my.cnf

Server-id=6log-bin=mysql-bin

2 restart mysql login and authorize

Mysql-uroot-p123456

Grant replication slave, replication client on *. * to 'repl'@'10.211.55.7' identified by' 123456'

The ip address is the ip address of the slave server

3 View log status

Show master status

Master2 configuration

1 enable binlog log function

Vim / etc/my.cnf

Server-id=8log-bin=mysql-bin

2 restart mysql login and authorize

Mysql-uroot-p123456

Grant replication slave, replication client on *. * to 'repl'@'10.211.55.7' identified by' 123456'

The ip address is the ip address of the slave server

3 View log status

Show master status

Slave configuration

1 modify the configuration file (note that the port launched by the default database of slave must close service mysql stop)

Vim / etc/my.cnf

[mysqld] binlog-ignore-db=mysql binlog_format=mixed expire_logs_days=7 slave_skip_errors=1062 relay_log=mysql-relay-bin log_slave_updates= 1[mysqld _ muliti] mysqld=/usr/bin/mysqld_safe mysqladmin=/usr/bin/mysqladmin user=root password=123456 [mysqld6] port=3306 datadir=/home/mysql/data6 pid-file=/home/mysql/data6/mysql.pid socket=/home/mysql/data6/mysql.sock user=mysql server-id=7 [mysqld8] port=3307 datadir=/home/mysql/data8 pid-file=/home/mysql/data8/mysql.pid socket= / home/mysql/data8/mysql.sock user=mysql server-id=7

2 initialize the build directory

/ usr/local/mysql/scripts/mysql_install_db-user=mysql-basedir=/usr/local/mysql-datadir=/home/mysql/data6 & / usr/local/mysql/scripts/mysql_install_db-user=mysql-basedir=/usr/local/mysql-datadir=/home/mysql/data8 &

3 modify directory permissions

Chown-R mysql/ home/mysql/data6chown-R mysql/ home/mysql/data8

4 start the service

Mysqld_multi-defaults-file=/etc/my.cnf start 6mysqld_multi-defaults-file=/etc/my.cnf start 8

5 login test (and do authorization separately)

Mysql-P 3306-S / home/mysql/data6/mysql.sock

Mysql > change master to master_host='10.211.55.6', master_user='repl', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=120;mysql > start slave

Mysql-P 3307-S / home/mysql/data8/mysql.sock

Mysql > change master to master_host='10.211.55.8', master_user='repl', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=120;mysql > start slave

That's how ok finished it.

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

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