文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

mysql数据库同步debug的示例分析

2024-04-02 19:55

关注

小编给大家分享一下mysql数据库同步debug的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

mysql的同步一直是个很重要的问题,也是一个难题,所幸提供了多种方法可以用来同步

在本文中我先给出mysql本身自带的方式master-slave方式,详尽的步骤如下:

1、prepare

### 需要修改主、从服务器的my.cnf文件###

1) master

mysql> grant replication client,replication slave on *.* to ‘repl’@'192.168.0.*’ identified by ‘xxxxxx’

=========================================================================

### 主服务器###

# Replication Master Server (default)

# binary logging is required for replication

log-bin=/mysql/bin-log

log-bin-index=/mysql/bin-log.index

#binlog_cache_size = 1M

binlog_do_db = test1

binlog_do_db = test2

#binlog_ignore_db =

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

server-id = 2370

=========================================================================

2) slave

mysql> grant replication client,replication slave on *.* to ‘repl’@'192.168.0.*’ identified by ‘xxxxxx’

=========================================================================

### 从服务器###

# required unique id between 2 and 2^32 - 1

# (and different from the master)

# defaults to 2 if master-host is set

# but will not function as a slave if omitted

server-id = 2379

#

# The replication master for this slave - required

master-host = 192.168.0.240

#

# The username the slave will use for authentication when connecting

# to the master - required

master-user = repl

#

# The password the slave will authenticate with when connecting to

# the master - required

master-password = xxxxxx

#

# The port the master is listening on.

# optional - defaults to 3306

master-port = 3306

#

# binary logging - not required for slaves, but recommended

#log-bin=/mysql/log/slavebin-log

master-info-file = /mysql/log/master.info

relay-log-info-file = /mysql/log/relay-log.info

replicate_do_db = test1

replicate_do_db = test2

#replicate_ignore_db = …

#replicate_do_table =

#replicate_ignore_table =

#replicate_wild_do_table =

#replicate_wild_ignore_table = …

#replicate_wild_ignore_table = temp\_subpost\_%

#replicate_rewrite_db=->

# 1062: dup key entry

# 1064: sql syntax

#slave_skip_errors = 1062,1064

slave_skip_errors = 1062

relay-log = /mysql/log/relay-log

relay-log-index = /mysql/log/relay-log.index

=========================================================================

### below step will start the work ###

=========================================================================

cd /opt/mysql/bin

ln -s /opt/mysql/share/mysql/mysql.server mysqlctl

=========================================================================

2、stop mysql

1) master: mysqlctl stop && ps auxww|grep mysql

2) slave: mysqlctl stop && ps auxww|grep mysql

3、start master’s mysql

mysqlctl start

ps auxww|grep mysql

mysql >flush tables;

mysql >show master status \G

mysql >reset master

mysqlctl stop

4、start slave’s mysql

mysqlctl start

ps auxww|grep mysql

mysql >stop slave

mysql >show slave status \G

mysql >reset slave;

mysqlctl stop

5、start master’s mysql

mysqlctl start

mysql >show master status \G

mysql >flush tables with read lock

mysql >show master status \G

## record the bin-log and positon ##

6、synchronization master’s datas to slave

rsync -avP “master’s datas” “slave’s datas directory”

7、start slave’s mysql

mysqlctl start –skip-slave-start

mysql >show slave status \G

mysql >change master to

-> MASTER_HOST=’master_host_name’,

-> MASTER_USER=’replication_user_name’,

-> MASTER_PASSWORD=’replication_password’,

-> MASTER_LOG_FILE=’recorded_log_file_name’,

-> MASTER_LOG_POS=recorded_log_position;

## Note:slave’s file and pos must be the same with with master’s ##

8、master

mysql >unlock tables;

9、slave

mysql >show slave status \G

## Note: Seconds_behind_master=0

## Slave_IO_Running=YES,Slave_SQL_Running=YES

10、checking the slave’s database updated real-time whether or not ??

以上是“mysql数据库同步debug的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯