构建MySQL主主复制架构
MySQL主主复制结构区别于主从复制结构。在主主复制结构中,两台服务器的任何一台上面的数据库存发生了改变都会同步到另一台服务器
Mysql主主复制架构配置
MySQL主主复制结构区别于主从复制结构。在主主复制结构中,两台服务器的任何一台上面的数据库存发生了改变都会同步到另一台服务器上,,这样两台服务器互为主从,并且都能向外提供服务。 这就比使用主从复制具有更好的响应性能。
配置过程
具体Mysql的安装我就不在阐述,在这一篇的Mysql的主从架构的配置中有详细介绍
erver1:192.168.1.108
server2: 192.168.1.110
1.创建用户并授权
server1:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'server2'@'192.168.1.110' IDENTIFIED BY 'server2';
server2:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'server1'@'192.168.1.108' IDENTIFIED BY 'server1';
2.修改Mysql的主配置文件
server1:
[mysqld]
server-id = 10
log-bin = mysql-bin
replicate-do-db = mydb
auto-increment-increment = 2 //每次增长2
auto-increment-offset = 1 //设置自动增长的字段的偏移量,即初始值为2
启动Mysql服务:
service mysqld restart
server2:
[mysqld]
server-id = 20
log-bin = mysql-bin
replicate-do-db = mydb
auto-increment-increment = 2 //每次增长2
auto-increment-offset = 2 //设置自动增长的字段的偏移量,即初始值为2
启动Mysql服务:
service mysqld restart
注:二都只有server-id和 auto-increment- offset不同
auto-increment-increment的值应设为整个结构中服务器的总数,本案例用到两台服务器,所以值设为2。
3.重新启动两个服务器
service mysqld restart
4.为了让两个数据库一样,我们备份其中一个数据库,然后在另一个数据库上恢复,这样是两个数据库一开始都是一样的。
在server1上操作:
mysqldump --databases nange > /tmp/nange.sql
在server2上操作:
创建一个与mydb同名的空数据库
mysql
> CREATE DATABASE mydb;
>\q
scp 192.168.1.108:/tmp/mydb.sql ./
mysql -uroot -p mydb
5.然后两个服务器相互通告二进制日志的位置并启动复制功能:
在server1上:
mysql
> CHANGE MASTER TO
> MASTER_HOST='192.168.1.110',
> MASTER_USER='server2',
> MASTER_PASSWORD='server2';
mysql > START SLAVE;
在server2上:
mysql
> CHANGE MASTER TO
> MASTER_HOST='192.168.1.108',
> MASTER_USER='server1',
> MASTER_PASSWORD='server1';
mysql > START SLAVE;
6.查看,并验证:
分别在两个数据库服务器上查看
mysql > START SLAVE;
然后查看数据库和表,你会发现内容是一样的,这样就是整个主主Mysql的架构的配置过程。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.
