当前位置:网站首页>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 )
边栏推荐
- SQLite queries the maximum value and returns the whole row of data
- Quantitative description of ANC noise reduction
- The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
- 算法-- 爬楼梯(Kotlin)
- 备忘一下jvxetable的各种数据集获取方法
- Embedded interview questions (IV. common algorithms)
- First acquaintance with CDN
- Jvxetable implant j-popup with slot
- [email protected] raspberry pie
- A master in the field of software architecture -- Reading Notes of the beauty of Architecture
猜你喜欢

Rustdesk builds its own remote desktop relay server

初识数据库

How can large websites choose better virtual machine service providers?

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
【SQL server速成之路】——身份验证及建立和管理用户账户
![[Jiudu OJ 08] simple search x](/img/a7/12a00c5d1db2deb064ff5f2e83dc58.jpg)
[Jiudu OJ 08] simple search x
![[force buckle]43 String multiplication](/img/fd/de63e6185af4b6293e748aaf7cee29.jpg)
[force buckle]43 String multiplication

ArcGIS应用基础4 专题图的制作

What preparations should be made for website server migration?

Jushan database appears again in the gold fair to jointly build a new era of digital economy
随机推荐
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
JDBC calls the stored procedure with call and reports an error
Game push image / table /cv/nlp, multi-threaded start
05. Security of blog project
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
jdbc使用call调用存储过程报错
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
Anti shake and throttling are easy to understand
SQLite queries the maximum value and returns the whole row of data
PDK工藝庫安裝-CSMC
Garbage collector with serial, throughput priority and response time priority
[experience] install Visio on win11
【华为机试真题详解】统计射击比赛成绩
[email protected]树莓派
B站刘二大人-反向传播
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
类和对象(一)this指针详解
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
After the project is released, index Html is cached
Pay attention to the details of pytoch code, and it is easy to make mistakes