日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql数据库同步 debug

發布時間:2025/7/14 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 ??

轉載于:https://blog.51cto.com/badboy6515/634960

總結

以上是生活随笔為你收集整理的mysql数据库同步 debug的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。