首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >创建MySQL从库

创建MySQL从库

作者头像
全栈程序员站长
发布2022-07-10 14:05:00
发布2022-07-10 14:05:00
2.3K0
举报

大家好,又见面了,我是全栈君。

我们知道Oracle有DataGuard实时备份数据。能够做主备切换,而MySQL也有自己的一套备库方案。称之为主从复制。

搭建MySQL从库是为了实时同步主库数据,同一时候也能够分担主库的读压力。对数据库端做成读写分离结构。

搭建MySQL主从库注意点:

1.主库和从库的 server-id 一定不能同样。

2.在主库创建replication slave账户。

grant replication slave on *.* to ‘repl’@’192.168.0.232’ identified ‘oracle’;

3.查看主库master状态

mysql> show master status \G *************************** 1. row *************************** File: mysql-bin.000005 Position: 251651 Binlog_Do_DB: Binlog_Ignore_DB: 1 row in set (0.00 sec)

4.配置从库

change master to -> master_host=’192.168.0.232′, -> master_user=’repl’, -> master_password=’oracle’, -> master_log_file=’mysql-bin.000005′, -> master_log_pos=251651;

5. 启动从库

slave start

show slave status\G

*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: *********** Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000005 Read_Master_Log_Pos: 463725968 Relay_Log_File: mysql-relay-bin.000006 Relay_Log_Pos: 463726114 Relay_Master_Log_File: mysql-bin.000005 Slave_IO_Running: Yes Slave_SQL_Running: Yes 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: 463725968 Relay_Log_Space: 873569451 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 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: 100

注意:

假设从库Slave_IO_Running: No/ Slave_SQL_Running: No

关闭slave

设置set GLOBALSQL_SLAVE_SKIP_COUNTER=1; 在开启slave

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年2月4,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档