首页 > 数据库 >mysql-8.0.x搭建主从

mysql-8.0.x搭建主从

时间:2023-03-12 19:22:26浏览次数:53  
标签:8.0 servyou slave log MASTER mysql master 主从

概述

master/slave用作备库的形式数据库的可用性

开干

env

  • centos7.x 2c4g x2
  • mysql 8.0.28

x01、mysql安装

x02、修改my.cnf

master

[mysql]
auto-rehash
default-character-set = utf8mb4
connect-timeout = 3

[mysqld]
server-id = 7670
port = 3306

#base
basedir = /servyou/mysql
datadir = /servyou/mysql_data

#innodb
default-storage-engine = INNODB
innodb_buffer_pool_size = 2G

#set character
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

#optimazed
skip-name-resolve

#default_authentication_plugin = mysql_native_password
authentication_policy = mysql_native_password

max_allowed_packet = 250M
lower_case_table_names = 1
max_connections = 2000
max_user_connections = 1500
explicit_defaults_for_timestamp = true
default-time-zone = system

#log
binlog_format = ROW
log-bin = mysql-bin
max_binlog_size = 1G
#expire_logs_days = 30
binlog_expire_logs_seconds = 2592000
slow_query_log = 1
long-query-time = 30
log_timestamps = SYSTEM
log_bin_trust_function_creators = 1

#master/slave optimized
gtid_mode = ON
enforce_gtid_consistency = ON
#log_slave_updates = 1    --deprecated
log_replica_updates = 1
#slave-parallel-workers = 4  --deprecated
replica_parallel_workers = 4
relay-log = relay-bin

#read_only = 1
#super_read_only = 1

[mysqld_safe]
socket = /servyou/mysql_data/mysql.sock
log-error = /servyou/mysql_data/mysql_error.log
pid-file = /servyou/mysql_data/mysqld.pid

slave

[mysql]
auto-rehash
default-character-set = utf8mb4
connect-timeout = 3

[mysqld]
server-id = 76701  ### master/salve 不能一样
port = 3306

#base
basedir = /servyou/mysql
datadir = /servyou/mysql_data

#innodb
default-storage-engine = INNODB
innodb_buffer_pool_size = 2G

#set character
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

#optimazed
skip-name-resolve

#default_authentication_plugin = mysql_native_password
authentication_policy = mysql_native_password

max_allowed_packet = 250M
lower_case_table_names = 1
max_connections = 2000
max_user_connections = 1500
explicit_defaults_for_timestamp = true
default-time-zone = system

#log
binlog_format = ROW
log-bin = mysql-bin
max_binlog_size = 1G
#expire_logs_days = 30
binlog_expire_logs_seconds = 2592000
slow_query_log = 1
long-query-time = 30
log_timestamps = SYSTEM
log_bin_trust_function_creators = 1

#master/slave optimized
gtid_mode = ON
enforce_gtid_consistency = ON
#log_slave_updates = 1    --deprecated
log_replica_updates = 1
#slave-parallel-workers = 4  --deprecated
replica_parallel_workers = 4
relay-log = relay-bin

### slave要开启禁止写
read_only = 1
super_read_only = 1

[mysqld_safe]
socket = /servyou/mysql_data/mysql.sock
log-error = /servyou/mysql_data/mysql_error.log
pid-file = /servyou/mysql_data/mysqld.pid

x03、创建repl账户及开启复制通道

create user on master

create user 'repl'@'172.%' identified by '123456';
grant replication slave on *.* to 'repl'@'172.%';
flush privileges;

on master

show master status;
SHOW BINARY LOGS;
show slave hosts;

open replication channel

#第一次安装pos ->FIRST
CHANGE MASTER TO
MASTER_HOST='192.168.211.128',
MASTER_USER='repl',
MASTER_PASSWORD='mysql',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;

#从特定的pos开始复制
change MASTER to MASTER_HOST = '172.24.20.22',
MASTER_USER = 'repl',
MASTER_PASSWORD = '123456',
MASTER_LOG_FILE = 'mysql-bin.000001',
MASTER_LOG_POS = 834;

start slave

start slave;
show slave status\G;

x04、测试主从复制

#slave测试,是否可以创建表及库

#master测试,进入创建库及表,看看slave节点是否有对应的数据

标签:8.0,servyou,slave,log,MASTER,mysql,master,主从
From: https://www.cnblogs.com/xiaochina/p/17019544.html

相关文章

  • 【项目实战】基于Python+Tkinter+MySQL的GUI简易酒店管理系统(附完整源码)
    1、项目说明基于python+Tkinter+MySQL的简易酒店管理系统项目实战项目需要安装pycharm社区版或专业版都可,MySQL以及项目所需的所有模块项目需要安装tkinter、pymysql......
  • mysql
    mysql数据库相关概念数据:数据库:存储数据的仓库,数据是有组织的进行存储数据库管理系统:操纵和管理数据库的大型软件SQL:结构化查询语言(structuredquerylanguage),是一套......
  • 力扣180(MySQL)-连续出现的数字(中等)
    题目:编写一个SQL查询,查找所有至少连续出现三次的数字。返回的结果表中的数据可以按 任意顺序 排列。查询结果格式如下面的例子所示: 解题思路:原表数据: 方法......
  • mysql数据库系统
    数据库的概念:数据库就是一个运行在系统上的软件,用于存储用户个人信息、用户的游戏资料等数据库是多个表的集合,是存储数据的仓库,以一定的组织方式存储的相互有关的数据数据库......
  • 【项目实战】基于Python+Django+MySQL的新闻发布系统(附完整源码)
    1、项目说明基于python+Django+Mysql的新闻发布系统项目实战项目需要安装pycharm专业版以及MySQL环境(环境搭建和破解可以看我的B站里的视频有讲解)首先需要创建数据库数......
  • mysql优化
    mysql使用总结针对字段判断casewhen字段判断then使用示例#建表语句CREATETABLE`user`(`id`int(255)NOTNULL,`name`varchar(255)DEFAULTNULL,`ag......
  • 【项目实战】基于Python+Django+MySQL的音乐网站系统(附完整源码)
    1、项目说明基于python+Django+Mysql的音乐网站系统项目实战项目需要安装pycharm专业版以及MySQL环境(环境搭建和破解可以看我的B站里《python环境配置》的视频里有讲解)......
  • 【项目实战】基于Python+Flask+MySQL的在线笔记管理系统
    1、项目说明基于python+Flask+mysql的在线笔记管理系统项目实战项目需要安装pycharm专业版,mysql数据库以及项目所需的所有模块创建数据库名称db_online_notes,然后执行sq......
  • MySQL中的函数
    1.函数函数与存储过程一样,也是一组预先编译好的SQL语句的集合,理解为批处理语句。将实现某个功能的一段代码封装起来,只暴露名字,隐藏具体实现过程。函数与存储过程的......
  • MySQL8中如何估算redo日志的大小
    先说公式:mysql>pagergrepsequence;showengineinnodbstatus\Gselectsleep(60);showengineinnodbstatus\Gnopager;mysql>select(<second_value>-<firs......