首页 > 数据库 >mysql 主从配置

mysql 主从配置

时间:2023-03-17 13:57:52浏览次数:36  
标签:slave 配置 replication Master master mysql MASTER 主从



# master修改密码,创建用户,授权用户

ALTER USER USER() IDENTIFIED BY 'mima';
create user 'root'@'%' identified WITH mysql_native_password by 'mima';
grant all on *.* to 'root'@'%' WITH GRANT OPTION;

create user 'replication'@'%' identified WITH mysql_native_password by 'mima';
grant replication slave,replication client on *.* to 'replication'@'%';
flush privileges;

 

 

#master配置文件
server_id=220
log_bin=master-binlog
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=1


#slave配置文件
server_id=221
log_bin=slave-binlog
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=1
skip-slave-start

 

#备份主库

mysqldump --all-databases -p >>all.sql

#还原从库

mysql -p < all.sql

 

#slave

#基于Gtid 的
CHANGE MASTER TO
MASTER_HOST='192.168.10.221',
master_user='replication',
master_password='mima',
master_port=3306,
MASTER_AUTO_POSITION = 1;

 

#基于binlog日志的

mysql> show master status\G;
*************************** 1. row ***************************
File: 30b61a8f81a5-bin.000003
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)

##########################

CHANGE MASTER TO
MASTER_HOST='172.17.0.2',
MASTER_USER='replication',
MASTER_PASSWORD='mima',
MASTER_PORT=3306,
MASTER_LOG_FILE='c30b61a8f81a5-bin.000003',
MASTER_LOG_POS=154;

mysql> start slave;

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.10.220
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-binlog.000002
Read_Master_Log_Pos: 8753
Relay_Log_File: mysql-slave-relay-bin.000002
Relay_Log_Pos: 3996
Relay_Master_Log_File: master-binlog.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

 

 

 

 

 

标签:slave,配置,replication,Master,master,mysql,MASTER,主从
From: https://www.cnblogs.com/liuyoushui/p/17226260.html

相关文章

  • Splunk DB Connect 连接MySQL报错CLIENT_PLUGIN_AUTH is required
    01、问题描述使用SplunkDBConnect连接MySQL数据库读库时,报错CLIENT_PLUGIN_AUTHisrequired,如下图:02、原因分析根据报错信息,查阅相关资料,了解到报错原因:目标数据库......
  • 力扣197(MySQL)-上升的温度(简单)
    题目:表: Weather编写一个SQL查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。返回结果 不要求顺序 。查询结果格式如下例。 解题思路:方法一:使用......
  • 华为 MPLS VPN 配置报告
    一、拓扑:二、需求:​1、CE1和CE3分别是总公司研发部和分公司研发部。​2、CE2和CE4分别是总公司非研发部和分公司非研发部。​3、CE1和CE3属于vpna。​4、CE2和CE......
  • Nginx_https配置
    server{#配置HTTPS的默认访问端口为443。#如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。#如果您使用Nginx1.15.0及以上版本,请使用list......
  • mysql select @params:= 的问题
    1、创建班级表createtableclass(idintprimarykeyauto_increment,titlevarchar(50))2、添加测试数据insertintoclassvalues(null,'小班'),(nul......
  • SpringBoot多数据源配置以及事务处理
    注:本文转自:https://www.toutiao.com/article/7204651968885686787/?log_from=4fd44355ebbb6_1679021148713背景在高并发的项目中,单数据库已无法承载大数据量的访问,因此需......
  • MySQL错误:Access denied for user 'root'@'%' to database 'xxx'
    本篇记录了我在遇到该问题,解决该问题的全部过程,相信自己,还是很强大的,希望对遇到相似问题的网友有所帮助~本人Linux服务器,Centos7版本,Mysql5.7.14。。。最初问题:使用N......
  • mysql不同版本的功能差异
    概述mysql不同版本的功能差异介绍mysql的官网下载地址http://dev.mysql.com/downloads/MySQLCommunityServer(社区版)社区版本,免费,但是Mysql不提供官方技术支持......
  • Winform中实现保存配置到文件/项目启动时从文件中读取配置(序列化与反序列化对象)
    场景Winform中实现序列化指定类型的对象到指定的Xml文件和从指定的Xml文件中反序列化指定类型的对象:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106466......
  • 力扣196(MySQL)-删除重复的电子邮箱(简单)
    题目:表: Person编写一个SQL删除语句来删除所有重复的电子邮件,只保留一个id最小的唯一电子邮件。以任意顺序返回结果表。(注意:仅需要写删除语句,将自动对剩余结......