当前位置:网站首页>MySQL database master-slave configuration
MySQL database master-slave configuration
2022-07-30 19:41:00 【bsegebr】
1. Install MySQL database
2. Modify the master database configuration
1. Set the service id in /etc/my.cnf (note: ensure that it is inconsistent with the slave database), restart the database
2. Query the basic data of the database master, and save the records for backup;
(1).mysql -u(userName)-p enter the database command line
(2). Enter show master status; query master data
Record file, Position data file "binlog.000015" and offset "2832";
3. Create a cross-domain account to ensure that the slave server can log in to the mysql database of the master server
createuser 'rep'@'%' identified by '1234567'; ----Create a mysql user for synchronization from the server
grant replication slave,replication client on . to 'rep'@'%'; ----Authorized created user permissions
(Note: If it is mysql8.0 or later, the encryption method needs to be modified, the command is as follows: alter user 'root'@'%' identified with mysql_native_password by 'root';)
flush privileges; ------ Immediately refresh the permissions to make the permissions changes take effect immediately
3. Modify the configuration of the slave database
1. Install the database on the slave server (guarantee the same version as the master database)
2. Log in to the main database cross-domain to ensure that the new cross-domain account can be used mysql -h "ip" -u"userName" -p
Entering the mysql data line means the link is successful
3. Modify the configuration of the slave database, the server_id is guaranteed to be inconsistent with the master database, and restart the database
4. If it is a newly installed database, it does not need to be processed, and the master-slave relationship is set directly. If there is data in the database, it needs to be synchronously initialized first, that is, to ensure that the contents of the master and slave databases are consistent;
5. Enter the commandLine to set the master-slave relationship
change master to master_host='the ip of the server where the master database is located', master_user='the account name of the set cross-domain account', master_password='password', master_log_file='in the master database masterfile name', master_log_pos='offset of master database master';
6. Start the slave server process
start slave;
7. View the slave server process status
show slave statusG;
Slave_IO_Running: write status
Slave_SQL_Running: local database running status
When both statuses are yes, it proves that the database master-slave status is set successfully
(1) If the Slave_IO_Running status is connecting, checkThe communication status of the two servers, if the ping result is normal, check the firewall status of the two servers, adjust the external access rights of the firewall or directly close the firewall (both master and slave servers need to be adjusted);
If the status of Slave_IO_Running is No, you need to check the error information, there are too many error information in the log, you can see the latest one displayed in the slave status
According to the error information;
(2) If the Slave_SQL_Running status is No, it is generally caused by the inconsistency of the initial data of the master and slave databases
In this state, you can try to close the slave database process;
stop slave;
Back up the master database, import the slave database, make the master and slave databases consistent, and then restart;
start slave;
> View the status of the slave database;
If an error is still reported, you can execute the skip process command;
set global sql_slave_skip_counter=1;
After restarting, query the status, and repeat the skip command if the same type of error is reported. Generally,Adjust 2-3 times;
4. Test
When the status is normal, you can add, delete, modify and check the database in the master database, and then check the data status of the database in the slave database.Completed from configuration.
Five, gtid-based master-slave relationship
When configuring the settings file of the master database, you need to configure the following parameters:
From the database settings file, the configuration parameters are as follows:
When changing the master parameter from the database, replace the master_log_file and master_log_pos parameters with the master_auto_position parameter (1. When using GTID-based replication MASTER_AUTO_POSITION = 1 2. After using GTID, want to revert to the old file-based replication protocol MASTER_AUTO_POSITION =0);
After the modification is completed, start the slave database process, start slave; check the running status of the slave database, show slave statusG;
The status is normal, you can test it;
Reference: https://zhuanlan.zhihu.com/p/335142300
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- [Private Series] All kinds of strange problems encountered in daily PHP
- centos7安装mysql8
- MindSpore:mindspore有没有类似tf.GradientTape()用来求解梯度的?
- 来了!东方甄选为龙江农产品直播带货
- MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
- Download and installation of the latest version of MySQL 8.0 under Linux (detailed steps)
- iPhone真是十三香?两代产品完全对比,或许上一代更值得买
- MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
- MindSpore:【语音识别】DFCNN网络训练loss不收敛
- Install MySQL tutorial under Linux
猜你喜欢
MindSpore:【JupyterLab】查看数据时报错
What is the difference between a cloud database and an on-premises database?
Typora设置标题自动标号
LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集
SimpleOSS第三方库libcurl与引擎libcurl错误解决方法
mysql慢查询优化
Spark学习:用spark实现ETL
【MindSpore1.2.0-rc1产品】num_workers问题
Download Win11 how to change the default path?Download Win11 change the default path method
深入浅出边缘云 | 3. 资源配置
随机推荐
golang日志库zerolog使用记录
【MindSpore1.2.0-rc1产品】num_workers问题
Linux download and install mysql5.7 version tutorial the most complete and detailed explanation
试写C语言三子棋
055 c# print
.eslintrc.js for musicApp
Install MySQL tutorial under Linux
MongoDB打破了原则引入SQL?
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
MySQL夺命10问,你能坚持到第几问?
启动前台Activity
阿里云武林头条活动分享
Start background services across processes
055 c# print
SimpleOSS第三方库libcurl与引擎libcurl错误解决方法
VBA batch import Excel data into Access database
第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
How architects grow
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
【MindSpore】多卡训练保存权重问题