mysql5.7主从同步配置 centos7(简洁步骤)

mysql5.7主从同步配置 centos7(简洁步骤)

1.主机配置

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
transaction-isolation = READ-COMMITTED
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256k
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
max_connections = 550
 
server-id = 1
log_bin = /var/lib/mysql/mysql_master.log
binlog_format = mixed
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
 
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
 
character_set_server = utf8
 
[client]
 
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
sql_mode=STRICT_ALL_TABLES
 
 
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

注意
server-id = 1
log_bin = /var/lib/mysql/mysql_slave.log

2.从机配置

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
transaction-isolation = READ-COMMITTED
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256k
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
max_connections = 550
 
server-id = 2
log_bin = /var/lib/mysql/mysql_slave.log
binlog_format = mixed
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
 
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
 
character_set_server = utf8
 
[client]
 
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
sql_mode=STRICT_ALL_TABLES
 
 
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

注意
server-id = 2
log_bin = /var/lib/mysql/mysql_slave.log

3.主从设置(主机)

  • 登陆主机 mysql
mysql -uroot -p
  • 创建同步专用账号
grant replication slave on *.* to 'repl'@'%' identified by '123456';
  • 查看状态
    查看主机master状态
show master status;

在这里插入图片描述

4.主从设置(从机)

  • 登陆从节点mysql(root角色)
mysql -uroot -p
  • 执行主从设置
change master to  master_host='192.168.6.6' ,master_user='repl',  master_password='123456',master_port=3306,master_log_file='mysql_master.000001',master_log_pos=578;

注意:
master_log_file、master_log_pos就是master的file、position

  • 起动从机
start slave;
  • 查看同步状态
show slave status \G;

在这里插入图片描述

常见问题

常见问题:Slave_SQL_Running = NO
这个需要重新从0开始同步主库与从库,操作如下:

master

#登陆mysql
mysql -uroot -p

RESET MASTER;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
EXIT;

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

#再次登陆mysql,执行解锁
mysql -uroot -p

UNLOCK TABLES;

slave

#导入数据
mysql -uroot -p < mysqldump.sql
# 进入mysql 执行
mysql -uroot -p

RESET SLAVE;
CHANGE MASTER TO master_host='192.168.88.203',\
                        master_user='repl',\
                        master_password='123456',\
                        MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
START SLAVE;
SHOW SLAVE STATUS;
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100393.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Yarn 安装与使用教程[通俗易懂]

    一、官网指引英文官网:Yarn英文官网中文文档:Yarn中文文档二、Yarn介绍Yarn是Facebook,Google,Exponent和Tilde开发的一款新的JavaScript包管理工具。你可以通过它使用全世界开发者的代码,或者分享自己的代码。代码通过包(package)(或者称为模块(module))的方式来共享。一个包里包含所有需要共享的代码,以及描述包信息的文件,称为package.json。它的优点是更快、更安全、更可靠。它的主要特性有离线模式、确定性

    2022年4月10日
    62
  • 用Python实现自动发消息,自定义内容,太省事了!「建议收藏」

    用Python实现自动发消息,自定义内容,太省事了!「建议收藏」自动发弹幕,想要多快有多快!

    2022年6月7日
    32
  • CSS横向菜单

    CSS横向菜单

    2021年8月20日
    59
  • C++学习——虚函数与纯虚函数

    C++学习——虚函数与纯虚函数引言:若要访问派生类中相同名字的函数,必须将基类中的同名函数定义为 虚函数,这样,将不同的派生类对象的地址赋给基类的指针变量后, 就可以动态地根据这种赋值语句调用不同类中的函数。一、虚函数的定义和使用可以在程序运行时通过调用相同的函数名而实现不同功能的 函数称为虚函数。定义格式为:virtual FuncName();一旦把基类的成员函数定义为虚函数,由基类所派生出来的所 有派生类中,…

    2022年8月18日
    11
  • mac idea 激活码_最新在线免费激活

    (mac idea 激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月30日
    185
  • 视频的行为识别「建议收藏」

    视频的行为识别「建议收藏」1.概述使用DL方法解决视频中行为识别/动作识别的问题解决思路有三个分支:分别是two-stream(双流)方法,C3D方法以及CNN-LSTM方法。本文将从算法介绍、算法架构、参数配置、训练集预处理、算法优势及原因、运行结果六个方面对每种算法进行阐释,并对每一个分支的算法集合总结自己的心得。本文暂不区分行为识别(ActivityRecognition)与动作识别(ActionRecog…

    2022年6月9日
    42

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号