MySQL8主主搭建

2023-12-24 08:01
文章标签 搭建 mysql8 主主

本文主要是介绍MySQL8主主搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

-- mysql8 主主搭建
mysql-8.0.35-linux-glibc2.12-x86_64.tar.xz

主1 : 192.168.2.160 
主2 : 192.168.2.161

--解压mysql-8.0.35-linux-glibc2.12-x86_64.tar.xz为mysql8

-- 初始化mysql8 (略)

-- 参数192.168.2.160

[root@19cdg01 mysql]# ps -ef| grep mysql
root      1552  1433  0 01:00 pts/0    00:00:00 su - mysql
mysql     1554  1552  0 01:00 pts/0    00:00:00 -bash
mysql     1602  1554  0 01:00 pts/0    00:00:00 /bin/sh ./mysqld_safe --defaults-file=/mysql/mysql8/my.cnf --user=mysql
mysql     1877  1602  0 01:00 pts/0    00:00:19 /mysql/mysql8/bin/mysqld --defaults-file=/mysql/mysql8/my.cnf --basedir=/mysql/mysql8 --datadir=/mysql/mysql8/data --plugin-dir=/mysql/mysql8/lib/plugin --log-error=/mysql/mysql8/data/error.log --pid-file=19cdg01.pid --socket=/mysql/mysql8/mysql.sock --port=3306
mysql     2123  1554  0 01:04 pts/0    00:00:00 ./mysql -uroot -h127.0.0.1 -p
root      4317  4118  0 01:47 pts/2    00:00:00 grep --color=auto mysql
[root@19cdg01 mysql]# cat /mysql/mysql8/my.cnf
[mysqld]
server_id=3306
admin_port=33062
mysqlx_port=33060
socket=/mysql/mysql8/mysql.sock
mysqlx_socket=/mysql/mysql8/mysqlx.sock
log-error=/mysql/mysql8/data/error.log
port=3306
basedir=/mysql/mysql8
datadir=/mysql/mysql8/data
log_bin=binlog
log_bin_index=/mysql/mysql8/data/binlog.index
gtid_mode=on
enforce_gtid_consistency=true
auto-increment-increment = 2
auto-increment-offset = 1binlog-ignore-db = mysql,information_schema,performance_schema,sys[client]
port=3306
socket=/mysql/mysql/mysql88888888.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
[root@19cdg01 mysql]#

-- 参数192.168.2.161

[root@19cdg02 ~]# ps -ef| grep mysql
root      1583  1438  0 01:00 pts/0    00:00:00 /bin/sh ./mysqld_safe --defaults-file=/mysql/mysql8/my.cnf --user=mysql
mysql     1855  1583  0 01:00 pts/0    00:00:20 /mysql/mysql8/bin/mysqld --defaults-file=/mysql/mysql8/my.cnf --basedir=/mysql/mysql8 --datadir=/mysql/mysql8/data --plugin-dir=/mysql/mysql8/lib/plugin --user=mysql --log-error=/mysql/mysql8/data/error.log --pid-file=19cdg02.pid --socket=/mysql/mysql8/mysql.sock --port=3306
root      2105  1438  0 01:04 pts/0    00:00:00 ./mysql -uroot -h127.0.0.1 -p
root      4303  4277  0 01:48 pts/2    00:00:00 grep --color=auto mysql
[root@19cdg02 ~]# cat /mysql/mysql8/my.cnf
[mysqld]
server_id=33061
admin_port=33062
mysqlx_port=33060
socket=/mysql/mysql8/mysql.sock
mysqlx_socket=/mysql/mysql8/mysqlx.sock
log-error=/mysql/mysql8/data/error.log
port=3306
basedir=/mysql/mysql8
datadir=/mysql/mysql8/data
log_bin=binlog
log_bin_index=/mysql/mysql8/data/binlog.index
gtid_mode=on
enforce_gtid_consistency=true
auto-increment-increment = 2
auto-increment-offset = 2binlog-ignore-db = mysql,information_schema,performance_schema,sys[client]
port=3306
socket=/mysql/mysql8/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
[root@19cdg02 ~]#

-- 开启半同步 (8.0和5.7的半同步插件,不一样。安装5.7的插件也可以,log中有提示,即将被淘汰)

--INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
--SET GLOBAL rpl_semi_sync_master_enabled=ON;
install plugin rpl_semi_sync_source soname 'semisync_source.so';
set global rpl_semi_sync_source_enabled=1;

-- 启动数据库

./mysqld_safe --defaults-file=/mysql/mysql8/my.cnf --user=mysql
./mysqld_safe --defaults-file=/mysql/mysql8/my.cnf --user=mysql

-- 连接mysql

./mysql -uroot -h127.0.0.1 -p
./mysql -uroot -h127.0.0.1 -p

-- 创建复制账号rep1

CREATE USER 'rep1'@'192.168.2.%' IDENTIFIED WITH 'mysql_native_password' BY 'mysql';
grant replication slave on *.* to 'rep1'@'192.168.2.%';
flush privileges;

-- 设置复制.没有指定具体的log和position,使用参数MASTER_AUTO_POSITION = 1

CHANGE MASTER TO master_host='192.168.2.160', master_port=3306,master_user='rep1',master_password='mysql',MASTER_AUTO_POSITION = 1;
CHANGE MASTER TO master_host='192.168.2.161', master_port=3306,master_user='rep1',master_password='mysql',MASTER_AUTO_POSITION = 1;
start slave ;
show slave status ;

## 出现的问题及解决方法
1 因为刚开始没有设置binlog-ignore-db,分别在两个库上都建立和删除过账号,导致复制冲突。
1 节点1 上,log  drop user 'rep1'@'192.168.2.%'失败,执行事务'94c47d50-a0a1-11ee-86c9-000c299429f9:5'失败

2023-12-23T06:00:49.431587Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /mysql/mysql8/mysqlx.sock
2023-12-23T06:00:49.456284Z 10 [ERROR] [MY-010584] [Repl] Replica SQL for channel '': Worker 1 failed executing transaction '94c47d50-a0a1-11ee-86c9-000c299429f9:5' at source log binlog.000004, end_log_pos 392; Error 'Operation DROP USER failed for 'rep1'@'192.168.2.%'' on query. Default database: ''. Query: 'drop user 'rep1'@'192.168.2.%'', Error_code: MY-001396
2023-12-23T06:00:49.458896Z 6 [ERROR] [MY-010586] [Repl] Error running query, replica SQL thread aborted. Fix the problem, and restart the replica SQL thread with "START REPLICA". We stopped at log 'binlog.000004' position 197
2023-12-23T06:01:00.804824Z 14 [Warning] [MY-010055] [Server] IP address '192.168.2.161' could not be resolved: Name or service not known
2023-12-23T06:01:00.806701Z 14 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
2023-12-23T06:01:49.442498Z 8 [System] [MY-014002] [Repl] Replica receiver thread for channel '': connected to source 'rep1@192.168.2.161:3306' with server_uuid=94c47d50-a0a1-11ee-86c9-000c299429f9, server_id=33061. Starting GTID-based replication.

2 节点2上,log  create user CREATE USER 'rep1'@'%' IDENTIFIED WITH 'mysql_native_password'  失败 ,执行事务'9fa8b4aa-a0a0-11ee-86d4-000c29a929d8:10'失败

023-12-23T06:01:00.641166Z 8 [System] [MY-014002] [Repl] Replica receiver thread for channel '': connected to source 'rep1@192.168.2.160:3306' with server_uuid=9fa8b4aa-a0a0-11ee-86d4-000c29a929d8, server_id=3306. Starting GTID-based replication.
2023-12-23T06:01:00.662057Z 9 [ERROR] [MY-010584] [Repl] Replica SQL for channel '': Worker 1 failed executing transaction '9fa8b4aa-a0a0-11ee-86d4-000c29a929d8:10' at source log binlog.000003, end_log_pos 1580; Error 'Operation CREATE USER failed for 'rep1'@'%'' on query. Default database: ''. Query: 'CREATE USER 'rep1'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA'', Error_code: MY-001396
2023-12-23T06:01:00.664259Z 6 [ERROR] [MY-010586] [Repl] Error running query, replica SQL thread aborted. Fix the problem, and restart the replica SQL thread with "START REPLICA". We stopped at log 'binlog.000003' position 197
2023-12-23T06:01:49.333516Z 14 [Warning] [MY-010055] [Server] IP address '192.168.2.160' could not be resolved: Name or service not known
2023-12-23T06:01:49.334585Z 14 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'

1 节点1上跳过事务

stop slave;
select @@server_uuid;                                            <<< 查看当前服务器的uuid,可以不执行
set session gtid_next='94c47d50-a0a1-11ee-86c9-000c299429f9:5';  <<< 这个事务失败,设置下一个执行的事务为这个事务
begin;commit;                                                    <<< 执行一个空事务,欺骗库,执行过了上面的事务
set session gtid_next='AUTOMATIC';                               <<< 自动执行下一个事务 

2 节点2上跳过事务

stop slave;
select @@server_uuid;
set session gtid_next='9fa8b4aa-a0a0-11ee-86d4-000c29a929d8:10';
begin;commit;
set session gtid_next='AUTOMATIC';

另一种解决方法 (未测试)
在会话层面关闭sql log ,set session sql_log_bin = 0;
然后执行缺失的sql 。(sql 可以通过查看binlog的日志获取)

END

这篇关于MySQL8主主搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/531102

相关文章

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Linux搭建Mysql主从同步的教程

《Linux搭建Mysql主从同步的教程》:本文主要介绍Linux搭建Mysql主从同步的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux搭建mysql主从同步1.启动mysql服务2.修改Mysql主库配置文件/etc/my.cnf3.重启主库my

国内环境搭建私有知识问答库踩坑记录(ollama+deepseek+ragflow)

《国内环境搭建私有知识问答库踩坑记录(ollama+deepseek+ragflow)》本文给大家利用deepseek模型搭建私有知识问答库的详细步骤和遇到的问题及解决办法,感兴趣的朋友一起看看吧... 目录1. 第1步大家在安装完ollama后,需要到系统环境变量中添加两个变量2. 第3步 “在cmd中

本地搭建DeepSeek-R1、WebUI的完整过程及访问

《本地搭建DeepSeek-R1、WebUI的完整过程及访问》:本文主要介绍本地搭建DeepSeek-R1、WebUI的完整过程及访问的相关资料,DeepSeek-R1是一个开源的人工智能平台,主... 目录背景       搭建准备基础概念搭建过程访问对话测试总结背景       最近几年,人工智能技术

5分钟获取deepseek api并搭建简易问答应用

《5分钟获取deepseekapi并搭建简易问答应用》本文主要介绍了5分钟获取deepseekapi并搭建简易问答应用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需... 目录1、获取api2、获取base_url和chat_model3、配置模型参数方法一:终端中临时将加

IDEA如何切换数据库版本mysql5或mysql8

《IDEA如何切换数据库版本mysql5或mysql8》本文介绍了如何将IntelliJIDEA从MySQL5切换到MySQL8的详细步骤,包括下载MySQL8、安装、配置、停止旧服务、启动新服务以及... 目录问题描述解决方案第一步第二步第三步第四步第五步总结问题描述最近想开发一个新应用,想使用mysq

Mycat搭建分库分表方式

《Mycat搭建分库分表方式》文章介绍了如何使用分库分表架构来解决单表数据量过大带来的性能和存储容量限制的问题,通过在一对主从复制节点上配置数据源,并使用分片算法将数据分配到不同的数据库表中,可以有效... 目录分库分表解决的问题分库分表架构添加数据验证结果 总结分库分表解决的问题单表数据量过大带来的性能

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)

《Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)》:本文主要介绍Python基于火山引擎豆包大模型搭建QQ机器人详细的相关资料,包括开通模型、配置APIKEY鉴权和SD... 目录豆包大模型概述开通模型付费安装 SDK 环境配置 API KEY 鉴权Ark 模型接口Prompt