当前位置: 首页 > article >正文

续:MySQL的并行复制

【示例】

如果数据复制的慢的话,就会导致主从数据不一致性;

有的企业需要数据保持强一致性;比如银行等;

日志回放默认是单线程;

#

mysql> show processlist;
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time   | State                                                  | Info             |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
|  6 | system user |           | NULL | Connect | 170990 | Waiting for master to send event                       | NULL             |
|  7 | system user |           | NULL | Connect |  23369 | Slave has read all relay log; waiting for more updates | NULL             |
| 12 | root        | localhost | NULL | Sleep   |  24065 |                                                        | NULL             |
| 13 | root        | localhost | NULL | Query   |      0 | starting                                               | show processlist |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
4 rows in set (0.00 sec)


#做日志的多线程回放;加快回访速度;

#上一个实验我们在slave2上做了延迟;这一个实验就不要在设定了SQL_Delay: 60延迟的slave上做,这样毫无意义!

master  slave1

slave1上:编辑主配置文件:

多线程上需要把gtid打开

[root@mysql2 ~]# vim /etc/my.cnf
[root@mysql2 ~]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=2
super_read_only=on
gtid_mode=on
enforce-gtid-consistency=on

slave-parallel-type=LOGICAL_CLOCK  #基于组提交
slave-parallel-workers=16  #开启线程数量
master_info_repository=TABLE  #master信息在表中记录,默认记录在/data/mysql//master.info
relay_log_info_repository=TABLE  #回放日志信息在表中记录,默认记录在/data/mysql/relay-log.info  #多线程回放,日志会成为瓶颈,设置这两条将日志记录在数据表里,而不是文件里

relay_log_recovery=ON  #日志回放恢复功能开启

[root@mysql2 ~]# cd /data/mysql/
[root@mysql2 mysql]# ls
auto.cnf         folian          ibtmp1       mysql2.pid               mysql.sock          relay-log.info
ca-key.pem       ib_buffer_pool  master.info  mysql2-relay-bin.000002  mysql.sock.lock     server-cert.pem
ca.pem           ibdata1         mysql        mysql2-relay-bin.000003  performance_schema  server-key.pem
client-cert.pem  ib_logfile0     mysql1.err   mysql2-relay-bin.index   private_key.pem     sys
client-key.pem   ib_logfile1     mysql2.err   mysql-bin.index          public_key.pem
#重启数据库

[root@mysql2 ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS! 

#查看进程:这里刚开始出现了问题

[root@mysql2 ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS! 
[root@mysql2 ~]# 2024-08-27T02:41:31.233896Z mysqld_safe A mysqld process already exists

#这里出错了我们并没有查看到应有的效果
[root@mysql2 ~]# mysql -uroot -predhat

mysql> show processlist;
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time   | State                                                  | Info             |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
|  6 | system user |           | NULL | Connect | 172796 | Waiting for master to send event                       | NULL             |
|  7 | system user |           | NULL | Connect |  25175 | Slave has read all relay log; waiting for more updates | NULL             |
| 12 | root        | localhost | NULL | Sleep   |  25871 |                                                        | NULL             |
| 14 | root        | localhost | NULL | Query   |      0 | starting                                               | show processlist |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
4 rows in set (0.01 sec)

mysql> exit;
Bye
[root@mysql2 ~]# ps aux | grep mysql
avahi       793  0.0  0.1  62268  2276 ?        Ss   Aug26   0:11 avahi-daemon: running [mysql1.local]
root      17093  0.0  0.0 113412  1608 ?        S    00:47   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql2.pid
mysql     17234  0.6 10.6 1603764 198588 ?      Sl   00:47   3:45 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql2.err --pid-file=/data/mysql/mysql2.pid --socket=/data/mysql/mysql.sock
root      22394  0.0  0.2 163396  4172 pts/3    S+   09:01   0:00 mysql -px xxxx
root      23902  0.0  0.0 112812   968 pts/1    S+   10:53   0:00 grep --color=auto mysql
[root@mysql2 ~]# kill 17093 
[root@mysql2 ~]# kill 17234
[root@mysql2 ~]# kill 22394
[root@mysql2 ~]# ps aux | grep mysql
avahi       793  0.0  0.1  62268  2276 ?        Ss   Aug26   0:11 avahi-daemon: running [mysql1.local]
root      23918  0.0  0.0 112812   968 pts/1    S+   10:54   0:00 grep --color=auto mysql

[root@mysql2 ~]# /etc/init.d/mysqld start
Starting MySQL...... SUCCESS! 
#成功解决并查看
[root@mysql2 ~]# mysql -uroot -predhat

mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time | State                                                  | Info             |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
|  1 | system user |           | NULL | Connect |    9 | Slave has read all relay log; waiting for more updates | NULL             |
|  3 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  4 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  5 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  6 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  7 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  8 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
|  9 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
| 10 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
| 11 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
| 12 | system user |           | NULL | Connect |   11 | Waiting for an event from Coordinator                  | NULL             |
| 13 | system user |           | NULL | Connect |   10 | Waiting for an event from Coordinator                  | NULL             |
| 14 | system user |           | NULL | Connect |   10 | Waiting for an event from Coordinator                  | NULL             |
| 15 | system user |           | NULL | Connect |   10 | Waiting for an event from Coordinator                  | NULL             |
| 16 | system user |           | NULL | Connect |   10 | Waiting for an event from Coordinator                  | NULL             |
| 18 | system user |           | NULL | Connect |    9 | Waiting for an event from Coordinator                  | NULL             |
| 19 | system user |           | NULL | Connect |    9 | Waiting for an event from Coordinator                  | NULL             |
| 20 | root        | localhost | NULL | Query   |    0 | starting                                               | show processlist |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
18 rows in set (0.00 sec)

#从上我们可以看出有16个SQL进程来做日志回放,但是最终还是要落到CPU性能上。

#多线程:使主从的数据差异尽可能减小,(数据库优化)


http://www.kler.cn/a/284816.html

相关文章:

  • 问:MySQL主从同步的机制梳理?
  • 华为大咖说 | 浅谈智能运维技术
  • OSS文件上传
  • 【信号处理】基于联合图像表示的深度学习卷积神经网络
  • MYSQL隔离性原理——MVCC
  • VMWare虚拟机NAT模式下与外部主机(非宿主机)通信
  • XtQuant是什么?哪家券商支持miniQMT,XtQuant?
  • 使用SQLite进行Python简单数据存储的线程安全解决方案
  • Centos服务器配置使用密钥登录
  • 【C++题解】1722 - 输出两位的巧数
  • Docker 部署 Kafka 可视化 Kafka-UI
  • Arco Voucher - 不知道有什么用的凭证单据录入表单插件
  • 简易STL实现 | Deque的实现
  • PyMOL的开源版和商业版如何选择 PyMOL开源版安装 PyMOL商业版安装 PyMOL安装教程 远程安装PyMOL正式版 官网版
  • PDF文本指令解析与文本水印去除
  • 【IDEA】一键重启多个服务
  • 游戏出海,燃动全球,“安全”如何通关?
  • 【C++】有关vector迭代器失效问题
  • 快速了解Git服务器端基础及基本操作命令(一)
  • mysql的group by怎么用
  • disk manager操作教程 如何使用Disk Manager组件 Mac如何打开ntfs格式文件
  • Open WebUI官方库:解锁人工智能服务的官方通道
  • git常见命令行及分支规范
  • MATLAB智能优化算法-学习笔记(1)——遗传算法求解0-1背包问题【过程+代码】
  • 通过css,js html结合实现第一个页面
  • 网络安全实训六(靶机实例DC-3)