当前位置:网站首页>mysql5.7.25主从复制(单向)
mysql5.7.25主从复制(单向)
2022-07-26 09:23:00 【为天空着色】
安装数据库:https://blog.csdn.net/u010533511/article/details/88033637
Master配置
1)my.cnf配置
vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=139 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
binlog-do-db=ztong #指定需要日志的数据库
binlog_format= MIXED #binlog日志格式,mysql默认采用statement,建议使用mixed
slave_skip_errors = 1062 #跳过主键冲突错误
2)重启mysql
service mysqld restart
3)在主服务器上建立帐户并授权slave
#mysql –u root –p 123456
mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by '123456';
//一般不用root帐号,“%”表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.135.139,加强安全。
4) 登录mysql,查询master的状态
mysql>show master status;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000010 | 591 | ztong | | |
注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化。
File: mysql-bin.000010 Position: 591 这两个值后面会用到
Slave配置
1)my.cnf配置
vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=141 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
2)重启mysql
service mysql restart
3)配置从服务器Slave:
#数据库复制同步语句 master_log_file:对应master的file
#master_log_pos:是获master 的日志文件位置对应master 的position
mysql> change master to master_host='192.168.135.139',master_port=3306,master_user='mysync',master_password='123456',master_log_file='mysql-bin.000010',master_log_pos=591;
mysql> start slave; //启动从服务器复制功能4) 检查从服务器复制功能状态:
mysql> show slave status\G;
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.135.139
Master_User: mysync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 591 //在当前的主服务器二进制日志中,SLAVE中的I/O线程已经读取的位置
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 320 //在当前的中继日志中,SQL线程已读取和执行的位置
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: Yes //I/O线程是否被启动并成功地连接到主服务器上
Slave_SQL_Running: Yes //SQL线程是否被启动
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: 591
Relay_Log_Space: 531
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: 0 //从服务器SQL线程和所属服务器I/O线程之间的时间差距,单位以秒计
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 139
Master_UUID: 383b83a3-3b1f-11e9-986d-000c295d359a
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
Slave_IO_Running: Yes 负责与主机的io通信
Slave_SQL_Running: Yes 负责自己的slave mysql进程
都是yes说明正常
测试:链接到数据库,创建数据库ztong ,创建一个测试表

如果需要重新配置从库
mysql> slave stop
mysql> change master to master_host='192.168.135.139',master_port=3306,master_user='mysync',master_password='123456',master_log_file='mysql-bin.000010',master_log_pos=591;
mysql> start slave;
边栏推荐
猜你喜欢

【Mysql】认识Mysql重要架构(一)

Study notes of dataX

Unity topdown character movement control

Selection and practice of distributed tracking system

The essence of attack and defense strategy behind the noun of network security

STM32+MFRC522完成IC卡号读取、密码修改、数据读写

ZXing简化版,转载

What are CSDN spaces represented by
![[MySQL] how to execute an SQL statement (2)](/img/7b/53f8756458cc318e2f417b1cc0c3f8.png)
[MySQL] how to execute an SQL statement (2)

Use of off heap memory
随机推荐
"No input file specified" problem handling
Study notes of canal
arcgis的基本使用1
Go intelligent robot alpha dog, alpha dog robot go
“No input file specified “问题的处理
微信小程序学习笔记2
arc-gis基础操作3
安卓 实现缓存机制,多种数据类型缓存
csdn空格用什么表示
Elastic APM installation and use
Personality test system V1.0
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
暑假第四周
大二上第二周学习笔记
微信小程序学习笔记1
838. Heap sorting
JVM command induction
Nuxt - Project packaging deployment and online to server process (SSR server rendering)
【线上问题】Timeout waiting for connection from pool 问题排查
Byte buffer stream & character stream explanation