mysql数据库同步debug

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-02 05:16 点击:

 

数据库的同步一直是个很重要的问题,也是一个难题,所幸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 >sho

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • mysql-mmm
      • mysqldump命令——MySQL数据库备份还原
      • Oracle数据导入MySQL的快捷工具:MySQL Migration Toolkit
      • 简简单单储存过程——循环一个select结果集
      • MySQL数据库十大优化技巧
      • Mysql主主复制架构配置
      • Mysql安装笔记
      • MySQL Stmt预处理提高效率问题的小研究
      • Mysql的Procedure 参数为NULL问题分析
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1