当前位置:网站首页>分布式数据库主从配置(MySQL)
分布式数据库主从配置(MySQL)
2022-07-07 09:17:00 【Java_李子陵】
分布式数据库主从配置(MySQL)
注意:默认已经安装了mysql,安装教程详见我的另一篇博客–springboot项目部署到阿里云服务器(centos7)_Java_李子陵的博客-CSDN博客_springboot部署到阿里云
我的主数据库和从数据库分别放在一个云服务器上,如果只有一个云服务器大家可以再电脑本机安装一个MySQL,需要注意的是
Windows系统下需要修改的配置文件为my.in
1.主数据库配置
修改my.cnf文件
vim /etc/my.cnf添加如下内容
server-id=1 #服务器ID,任意一个整数 log-bin=mysql-bin #开启日志记录 binlog-do-db=db_test #只同步配置到这个数据库,如果复制多个数据库,重复设置这个选项即可如图所示

重启MySQL
systemctl restart mysqld登录MySQL,测试配置是否成功
登录MySQL
mysql -uroot -p创建对应的数据库(与配置文件中的保持一致:bindlog-do-db=db_test)
create database db_test检查主库状态,如下图所示,则配置成功
show master status

2.从数据库配置
修改my.cnf文件
vim /etc/my.cnf添加如下内容
server-id=2 #服务器ID,任意一个整数,和主库不同即可如图所示

重启MySQL
systemctl restart mysqld登录MySQL,测试配置是否成功
登录MySQL
mysql -uroot -p创建对应的数据库(与主数据库配置文件中的保持一致:bindlog-do-db=db_test)
create database db_test依次执行如下命令
stop slave注意:具体内容需要自己填
change master to master_host='主数据库服务器IP', master_user='主数据库用户名', master_password='主数据库密码', master_log_file='mysql-bin.000005', #与图2 File值保持一致 master_log_pos=322; #与图2 Position值保持一致start slaveshow slave status- 如果出现两个Yes则配置成功(如下图所示)

检测结果
在主数据库的db_test数据库任意创建一个数据库表,再添加几条测试数据,会发现从数据库会自动创建相应的数据库表和数据
边栏推荐
- Creative information was surveyed by 2 institutions: greatdb database has been deployed in 9 places
- 2021-05-21
- VR development optimization
- [untitled]
- 网络协议 概念
- [C #] the solution of WinForm operation zoom (blur)
- Eth trunk link switching delay is too high
- Unity websocket server
- 基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】
- After the uniapp jumps to the page in onlaunch, click the event failure solution
猜你喜欢
随机推荐
什么是高内聚、低耦合?
Transaction rolled back because it has been marked as rollback-only解决
Arduino board description
软件设计之——“高内聚低耦合”
About the application of writing shell script JSON in JMeter
Use of dotween
Creative information was surveyed by 2 institutions: greatdb database has been deployed in 9 places
Realize ray detection, drag the mouse to move the object and use the pulley to scale the object
基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】
Poj1821 fence problem solving Report
Unity downloads files through the server address
[untitled]
Eth trunk link switching delay is too high
测试开发基础,教你做一个完整功能的Web平台之环境准备
请问申购新股哪个证券公司开户是最好最安全的
基于华为云IOT设计智能称重系统(STM32)
Add a self incrementing sequence number to the antd table component
Une fois que l'uniapp a sauté de la page dans onlaunch, cliquez sur Event Failure resolution
uniapp 在onLaunch中跳轉頁面後,點擊事件失效解决方法
科普达人丨一文弄懂什么是云计算?







![[untitled]](/img/8e/e968d4629004bb0c3ee70328b6777b.jpg)

