当前位置:网站首页>Mysql database master-slave cluster construction
Mysql database master-slave cluster construction
2022-07-06 05:43:00 【Python's path to immortality】
List of articles
1 preparation
1 Choose a server as the master server , Back up the data needed on the server
2 Install from library MySQL, It needs to be consistent with the version of the main server
3 Synchronize the data on the master server to the slave Library ( The master-slave cluster will only synchronize the data operations after the cluster is created , The original data will not be synchronized )
2 Configure the main database
Modify the configuration file
vim /etc/my.cnf
Add the configuration
[mysqld]
log-bin=mysql-bin
server-id=1
restart mysql service (centOS 7+)
systemctl restart mysqld
Use the command line to root User access MySQL
mysql -u root -p
Input password , Get into
Create a user with synchronization permission from the node
GRANT REPLICATION SLAVE ON *.* TO 'userName'@'%' IDENTIFIED BY 'yourPassword';
among userName Username ,yourPassword Is password
Refresh the permissions
FLUSH PRIVILEGES;
Query the main database status
show master status;
Record File 、Position Value of field
among File For operation log file ,Position Is the pointer position , These two fields are the key to data synchronization

3 Configure slave
Modify the configuration file
vim /etc/my.cnf
Add the configuration
[mysqld]
server-id=2
Be careful : Of every server server-id Can't repeat
restart mysql service (centOS 7+)
systemctl restart mysqld
Use the command line to root User access MySQL
mysql -u root -p
Input password , Get into
Execute synchronization statements
CHANGE MASTER TO MASTER_HOST='masterServerIp', MASTER_PORT=masterPort, MASTER_USER='masterUser', MASTER_PASSWORD='masterPassword', MASTER_LOG_FILE='masterLogFile', MASTER_LOG_POS=masterPosition;
among masterServerIp Main library server address (ip Or domain name )
masterPort Give priority to the library mysql port ( You need to ensure that the Internet is accessible )
masterUser For the user just created to synchronize data to the slave Library
masterPassword It is the user password just created for synchronizing data to the slave Library
masterLogFile Log file name of the main library , Corresponding fields File
masterPosition Main library pointer position , Corresponding fields Position
Start synchronization from the library
start slave;
Query the synchronization status of the slave Library
show slave status\G;
Mainly focus on fields : Slave_IO_Running,Slave_SQL_Running, The values of these two fields are Yes Then the slave library synchronization status is good

thus , The configuration of the master-slave cluster has been basically completed
4 Set a read-only user from the Library
Log in from library , Add read only users
GRANT SELECT ON *.* TO 'userName'@'%' IDENTIFIED BY 'yourPassword';
among userName User name for database ,yourPassword For the user password
Refresh the permissions
FLUSH PRIVILEGES;
Use a read-only user when connecting from the Library
5 Recommended references
MySQL Cluster deployment ( The use of multiple MySQL Example simulation )
边栏推荐
猜你喜欢

初识数据库

B站刘二大人-线性回归 Pytorch

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

05. Security of blog project

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

PDK工藝庫安裝-CSMC

02. Develop data storage of blog project

First acquaintance with CDN

巨杉数据库再次亮相金交会,共建数字经济新时代

Summary of deep learning tuning tricks
随机推荐
Station B, Master Liu Er - back propagation
[imgui] unity MenuItem shortcut key
[detailed explanation of Huawei machine test] statistics of shooting competition results
HAC cluster modifying administrator user password
28io stream, byte output stream writes multiple bytes
SequoiaDB湖仓一体分布式数据库2022.6月刊
Application Security Series 37: log injection
01. Project introduction of blog development project
Vulhub vulnerability recurrence 67_ Supervisor
Garbage collector with serial, throughput priority and response time priority
YYGH-11-定时统计
RustDesk 搭建一个自己的远程桌面中继服务器
ArcGIS应用基础4 专题图的制作
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Note the various data set acquisition methods of jvxetable
[experience] install Visio on win11
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Solution of QT TCP packet sticking
02. Develop data storage of blog project
[email protected] raspberry pie