当前位置:网站首页>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;
边栏推荐
- Apple generated and verified tokens for PHP
- Basic use of Arc GIS 2
- MySQL transaction
- 【Flutter -- 布局】Align、Center、Padding 使用详解
- 李沐d2l(四)---Softmax回归
- Windows backs up the database locally by command
- MySQL strengthen knowledge points
- 原根与NTT 五千字详解
- Codeworks DP collection
- Nuxt - Project packaging deployment and online to server process (SSR server rendering)
猜你喜欢

csdn空格用什么表示

OFDM 十六讲- OFDM

arc-gis的基本使用2

Nuxt - Project packaging deployment and online to server process (SSR server rendering)

arcgis的基本使用4

jvm命令归纳

Windows通过命令备份数据库到本地

语音聊天app源码——钠斯直播系统源码
![[MySQL] detailed explanation of MySQL lock (III)](/img/3c/c6b5aa5693e6e7b5730a286d988c82.png)
[MySQL] detailed explanation of MySQL lock (III)

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
随机推荐
760. String length
JVM触发minor gc的条件
Server memory failure prediction can actually do this!
Use of off heap memory
语音聊天app源码——钠斯直播系统源码
李沐d2l(四)---Softmax回归
Does volatile rely on the MESI protocol to solve the visibility problem? (next)
Where are the laravel framework log files stored? How to use it?
2B和2C
Innovus is stuck, prompting x error:
What is the difference between NFT and digital collections?
Basic use of ArcGIS 1
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
What are CSDN spaces represented by
Study notes of canal
Original root and NTT 5000 word explanation
(2006, MySQL server has gone away) problem handling
省政府召开全省高温天气安全防范工作电视电话会议
2022 mobile crane driver test question simulation test question bank simulation test platform operation
TabbarController的封装