Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284383
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -10
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-05 09:11
文章分类
文章存档

2015年(1)

2014年(6)

2013年(8)

2012年(1)

2011年(6)

2010年(2)

2009年(16)

2008年(44)

我的朋友

分类: Mysql/postgreSQL

2009-12-04 22:44:36

实例解读mysqldump参数--master-data

先来看看官方文档的解释
Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating.
If the option value is 2, the CHANGE MASTER TO statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded. If the option value is 1, the statement takes effect when the dump file is reloaded. If the option value is not specified, the default value is 1.
大概就这么个意思:这个参数在建立slave数据库的时候会用到,当这个参数的值为1的时候,mysqldump出来的文件就会包括CHANGE MASTER TO这个语句,CHANGE MASTER TO后面紧接着就是fileposition的记录,fileposition记录的位置就是slavemaster端复制文件的起始位置。默认情况下这个值是1
当这个值是2的时候,chang master to也是会写到dump文件里面去的,但是不会有上面那个作用了thus is information only
翻译过来真感觉拗口,呵呵,凑活看看吧。上实例!
一、先dump一个库
[root@HI0-OA-nagios ~]# mysqldump -uroot -pdfs123 --master-data=1 nagios > dumpfile
二、观察fileposition的值,此时的table是被lock住不能写入的
mysql> show master status;
+------------------+-----------+--------------+------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000016 | 760292258 |              |                  |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> show master status;
+------------------+-----------+--------------+------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000016 | 760292258 |              |                  |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> show master status;
+------------------+-----------+--------------+------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000016 | 760292258 |              |                  |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)
三、观察dump出来的文件,fileposition的值和上面是相同的
[root@HI0-OA-nagios ~]# grep -i "CHANGE MASTER TO" dumpfile
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000016', MASTER_LOG_POS=760292258;
四、编辑slave端配置文件如下
[mysqld]
port            = 3306
socket          = /usr/local/mysql/var/mysql.sock
skip-locking
key_buffer = 64M
max_allowed_packet = 16M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
server-id = 3
master-host=10.83.200.153
master-port=3306
master-user=repl
master-password=slavepass
master-connect-retry=60
五、重启slavemysql
Service mysql restart
六、此时netstat -an|grep 3306 看到slavemaster的连接已经建立。现在不需要它们之间连接,登陆slave端,执行stop slave,连接成功断开
七、Mysqldump 导入master 导出的文件dumpfile
八、开启slave端同步
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
在这一步骤,如果--master-data 参数为二,此时你会发现你还需要输入
CHANGE MASTER TO
  MASTER_HOST='master2.mycompany.com',
  MASTER_USER='replication',
  MASTER_PASSWORD='bigs3cret',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='master2-bin.001',
  MASTER_LOG_POS=4,
  MASTER_CONNECT_RETRY=10;
类似的参数后,才能继续执行start slave。当然这里你也可以写到配置文件中去
九、查看slave端状态,大功告成
mysql> show processlist\G;
*************************** 1. row ***************************
     Id: 6
   User: root
   Host: localhost
     db: nagios
Command: Query
   Time: 0
  State: NULL
   Info: show processlist
*************************** 2. row ***************************
     Id: 7
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 27
  State: Waiting for master to send event
   Info: NULL
*************************** 3. row ***************************
     Id: 8
   User: system user
   Host:
     db: nagios
Command: Connect
   Time: 2958
  State: updating
   Info: DELETE FROM nagios_servicechecks WHERE instance_id='1' AND start_time
3 rows in set (0.01 sec)

本文出自 “一代小怪追大怪” 博客,请务必保留此出处http://asmboy001.blog.51cto.com/340398/197750

阅读(1790) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~