MySQL最常用的架构就是主从复制了,其实主从复制有很多选项,特别是在从库端,我们可以设置复制过滤,比如说忽略某张表或某个库。这些过滤选项都是可以在线修改而不用重启的。原来对这块了解不多,最近看了下相关资料,个人觉得这个功能还是很方便的,本篇文章会将这块内容分享给大家。
线上业务同学通常都会自己先搭建一套MySQL服务,自己维护,自己折腾,等到项目要上线,或者遇到某种性能瓶颈的时候,就会想到托管给DBA,这几天我们就遇到了这样一个场景。
STATEMENT模式(SBR) 每一条会修改数据的sql语句会记录到binlog中。优点是并不需要记录每一条sql语句和每一行的数据变化,减少了binlog日志量,节约IO,提高性能。缺点是在某些情况下会导致master-slave中的数据不一致(如sleep()函数, last_insert_id(),以及user-defined functions(udf)等会出现问题)
在上一篇文章《深入了解MySQL多源复制》中,介绍了MySQL多源复制的相关内容,本文将继续讲解MySQL多源复制,主要内容是过滤复制以及在已有复制过滤配置中新增复制对象;
墨墨导读:MySQL从8.0.17开始新增了克隆Clone技术,可以在线进行MySQL的本地克隆或远程克隆,从此搭建从库可以不再需要备份工具来实现了,本文分享Clone技术在线搭建主从复制全过程,希望对大家有帮助。
主从数据不一致对DBA来说是一个比较头疼的事情,刚接触MySQL时,遇到这种问题我一般采用重新还原备库的方式恢复数据,这对我来说是个很痛苦的过程。今天就来介绍两款pt工具,通过这两款工具可以针对数据不一致的情况进行快速检测和修复。
今天是周五,最近睡眠不好,一整天都浑浑噩噩的,状态不是很好,周五了,准备早点回家,早点休息了,今天的内容写写线上的一个案例,主要是关于主从复制过程中的replicate-gnore_table参数的,废话不多说,开始写。
前两天 MTSC 2018 在北京国际会议中心圆满召开,并取得非常好的反响,虽然临时有事,没去成,但还是非常赞许为此会议付出的朋友和小伙伴们~
系统:centos7 主库 M:192.168.16.12:3306 从库 S:192.168.16.15:3306 主从复制:传统复制
Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql instance(我们称之 Slave)。在 Master 与 Slave 之间的实现整个复制过程主要由三个线程来完成,其中两个线程(Sql线程和IO线程)在 Slave 端,另外一个线程(IO线程)在 Master 端。 要实现 MySQL 的 Replication ,首先必须打开 Master 端的Binary Log(mysql-bin.xxxxxx)功能,否则无法实现。因为整个复制过程实际上就是Slave从Master端获取该日志然后再在自己身上完全 顺序的执行日志中所记录的各种操作。打开 MySQL 的 Binary Log 可以通过在启动 MySQL Server 的过程中使用 “—log-bin” 参数选项,或者在 my.cnf 配置文件中的 mysqld 参数组([mysqld]标识后的参数部分)增加 “log-bin” 参数项。
MySQL 8.0.17的克隆插件允许在本地或从远程 MySQL 实例在线克隆数据,从此搭建从库可以不再需要备份工具(PXB或mysqldump)来实现了。克隆数据是存储在 InnoDB 其中的数据的物理快照,其中包括库、表、表空间和数据字典元数据。克隆的数据包含一个功能齐全的数据目录,允许使用克隆插件进行 MySQL 服务器配置。
MySQL复制功能提供分担读负载。 基于二进制日志的复制是异步的,那么复制有什么好处? 1.实现在不同服务器上的数据分布,利用二进制日志增量进行,不需要太多带宽,但是使用基于行的复制在进行大批量的更改时,会对带宽带来一定的压力。特别是跨IDC环境下进行复制,应该分批进行。 2.实现数据读取的负载均衡。可以通过DNS轮询的方式把程序的读连接分配到不同的备份数据库中。还有可以通过LVS+Keepalived等等。 3.增强了数据安全性,利用备库的备份来减少主库负载,还可以避免单点故障。值得注意的是,复制并不能替代备份。 4.实现数据库在线升级。
它并非在slave上执行操作,修改不一致数据,而是在master上重新插入当前值,通过同步而影响slave,从而解决数据的不一致(指定用户需要足读写权限)
断电后恢复,启动线下数据库,启动备库start slave报错io_thread没有启动成功
先来回顾一下MySQL的二进制知识点。基于Row格式的日志可以避免MySQL主从复制中出现的主从不一致问题。在一个sql语句修改了1000条数据的情况下,基于段的日志格式只会记录这个sql语句。而基于row的日志格式会有1000条记录来记录每一行的数据修改。
随着应用业务数据不断的增大,应用的响应速度不断下降,在检测过程中我们不难发现大多数的请求都是查询操作。
今天中午,搭建好的一套主从环境中磁盘报警,登陆到相关环境,发现是MySQL的错误日志量非常大,于是使用tail -f命令查看了日志文件,发现该错误日志增长的速度非常快,日志内容为:
pt-table-checksum是一个基于MySQL数据库主从架构在线数据一致性校验工具。其工作原理在主库上运行, 通过对同步的表在主从段执行checksum, 从而判断数据是否一致。在校验完毕时,该工具将列出与主库存在差异的对象结果。
启动mysql并且开启同步 [root@slave02 mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.27-75.0-log Percona Server (GPL), Release 75.0, Revision 8bb53b6 Copyright (
转:题记:关于mysql 同步复制技术的文章,M-S方式的非常多,本篇是我做的M-M模式的测试记录: 一。前期准备 机器A:ip地址 192.168.1.210 (maste1) 机器B:ip地址 192.168.1.211 (master2) 机器A同时充当Slave角色,为便于区分,名称设为 Slave2 机器B同时充当Slave角色,为便于区分,名称设为 Slave1 假设两台机器都已经安装好mysql,安装路径假设/usr/local/mysql/下,并假设 mysql配置文件my.cnf存放在/etc/下 二。修改机器A中mysql配置文件/etc/my.cnf 在[mysqld]配置段添加如下字段
给内部一个数据库做异地热备,热备部分采用了 MariaDB 的 galera 集群模式。然后挑选其中一台作为 Slave 和深圳主集群做主从同步。
执行同步 [root@slave-test mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.26-74.0-log Percona Server (GPL), Release 74.0, Revision 32f8dfd Copyright (c) 200
安装MySQL5.7,主数据库为192.168.2.221,从数据库为192.168.2.222,服务器内存8G
所有的关系型数据库都存在一个通病性能差,在企业中如果用户量特别打,将所有的数据都存放在一台服务器上,其性能时远远达不到要求的。所以需要使用一些手段来解决其性能的问题。 提升性能的方式有向上扩展以及向外扩展 向上扩展(Scale Up):使用更新更好的硬件,但硬件在怎么更新也有其性能的极限。盲目的向上扩展无法结局根本的问题 向外扩展(Scale Out):就是使用多台机器分摊压力来提供服务
MySQL的复制功能是构建基于MySQL的大规模、高性能应用的基础。复制功能不仅有利于构建高性能的应用,同时也是高可用性、可扩展性、灾难恢复、备份以及数据仓库等工作的基础。
问题: 在mysql主从或者mysql分布式架构某些时候主从中断,经分析发现重复创建用户导致。
启动mysql并且开启同步 [root@slave02 mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.27-75.0-log Percona Server (GPL), Release 75.0, Revision 8bb53b6 Copyright
前几天,手动搭建一个mysql主从复制集群,今天在执行过程中,出现如下错误:Error 'Can't drop database 'test'; database doesn't exist' on query. Default database: 'test'. Query: 'drop database test'。
刚刚抽空做了一下MYSQL 的主主同步。 把步骤写下来,至于会出现的什么问题,以后随时更新。这里我同步的数据库是TEST 1、环境描述。 主机:192.168.0.231(A) 主机:192.168.0.232(B) MYSQL 版本为5.1.21 2、授权用户。 A: mysql> grant replication slave,file on *.* to 'repl1'@'192.168.0.232' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) B: mysql> grant replication slave,file on *.* to 'repl2'@'192.168.0.231' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 然后都停止MYSQL 服务器。 3、配置文件。 在两个机器上的my.cnf里面都开启二进制日志 。 A: user = mysql log-bin=mysql-bin server-id = 1 binlog-do-db=test binlog-ignore-db=mysql replicate-do-db=test replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=1 B: user = mysql log-bin=mysql-bin server-id = 2 binlog-do-db=test binlog-ignore-db=mysql replicate-do-db=test replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=2 至于这些参数的说明具体看手册。 红色的部分非常重要,如果一个MASTER 挂掉的话,另外一个马上接管。 紫红色的部分指的是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。 4、重新启动MYSQL服务器。 在A和B上执行相同的步骤 [root@localhost ~]# /usr/local/mysql/bin/mysqld_safe & [1] 4264 [root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'. /usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected 071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data 5、进入MYSQL的SHELL。 A: mysql> flush tables with read lock\G Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row *************************** File: mysql-bin.000007 Position: 528 Binlog_Do_DB: test Binlog_Ignore_DB: mysql 1 row in set (0.00 sec) B: mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row **************************
版权声明:本文为耕耘实录原创文章,各大自媒体平台同步更新。欢迎转载,转载请注明出处,谢谢
一、问题描述 [root@mysql-slave ~]# mysql -uroot -pXXX mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 44883881 Server version: 5.7.23-log MySQL
1062错误----主键冲突,出现这种情况就是从库出现插入操作,主库又重新来了一遍,iothread没问题,sqlthread出错
*************************** 1. row ***************************
复制是指将主库的ddl,dml等操作通过binlog日志,传输到复制服务器,副本进行回放这些日志,从而使得从库和主库数据保存同步的工作模式
MySQL复制是一个非常强大的特性,它允许我们将一个MySQL数据库服务器(主服务器)的数据复制到一个或多个其他MySQL数据库服务器(从服务器)。但在某些场景下,我们可能不希望所有的数据都被复制。例如,可能有些数据库或表我们想要在主服务器上保留,而不想让它们被复制到从服务器。MySQL提供了几个配置选项,可以帮助我们实现这个目的。这些选项包括Replicate_Ignore_DB,Replicate_Ignore_Table,Replicate_Wild_Ignore_Table和Replicate_Ignore_Server_Ids。在本文中,我们将详细介绍这些配置选项的作用和如何使用它们。
# NOTE connect_timeout: A largevalue of this setting can create a denial of service vulnerability.
业务方有个需求,需要将node1上的employees库的departments 、dept_manager 这2张表同步到 node2 的 hellodb 库下面。
今天早上来到公司,遇到了一个主从复制的报错问题,虽然解决的过程比较快,但是我感觉还是有一定的借鉴意义,遇到类似的错误code,大家可以参考一下:
重启mysql [root@upgrade-slave ~]# /etc/init.d/mysql stop Shutting down MySQL (Percona Server)... [ OK ] [root@upgrade-slave ~]# /etc/init.d/mysql start Starting MySQL (Percona Server)........... [ OK ] [root@upgrade-
以上就是mysql两种事务类型,希望对大家有所帮助。更多mysql学习指路:Mysql
1594这个错误看起来挺严重的,会提示你binlog文件或者Relay log损坏了,例如binary log is corrupted、relay log is corrupted之类的看起来很吓人是吧,多数是由于掉电引发的,这也说明了机房配备UPS的重要性。本文来自真实生产案例,感谢网友加内特提供,本人加以故障重现校验。一起来看下如何解决吧。
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=10.1.1.201 --mysql-port=3320 --mysql-user=root --mysql-password='xxx@2021' --mysql-db=ww_test --tables=10 --table_size=100000 --mysql_storage_engine=Innodb --threads=2 --time=3000 --report-interval=10 --rand-type=uniform run
mysql 5.5.28-log> show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 88.88.88.88 Master_User: replicate Master_Port: 3306 Connect_Retry: 60 Master_Log_File: testdbbinlog.000005 Read_Master_Log_Pos: 98359687 Relay_Log_File: mysql-relay-bin.000020 Relay_Log_Pos: 4 Relay_Master_Log_File: testdbbinlog.000005 Slave_IO_Running: No Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 98359687 Relay_Log_Space: 107 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
说明: 环境 mysql-master:172.16.200.43 mysql-slave:172.16.200.44 系统:centos7 版本:MySQL5.6.35
前几天,有读者在后台留言问我可有基于Gtid的Mysql主从同步的文章,我记得历史文章应该有提及过,也有可能是只是提及,可能没有详细的过程介绍,所以,今天,民工哥就给大家安排一波。
之前遇到的一个主从复制的报错问题,虽然解决的过程比较快,但是我感觉还是有一定的借鉴意义,遇到类似的错误code,大家可以参考一下:
1032错误----现在生产库中好多数据,在从库误删了,生产库更新后找不到了,现在主从不同步了,再跳过错误也没用,因为没这条,再更新还会报错
主服务器上 binlog-do-db= //仅同步指定的库(多个库,可以用“ , ”逗号分隔)——>英文的逗号 , binlog-ignore-db= //忽略指定库 从服务器上 replicate_do_db= //仅同步指定的库 replicate_ignore_db= //忽略指定库 replicate_do_table= //仅同步指定的表 replicate_ignore_table= //忽略指定表, - 例
我们知道Oracle有DataGuard实时备份数据。能够做主备切换,而MySQL也有自己的一套备库方案。称之为主从复制。
领取专属 10元无门槛券
手把手带您无忧上云