免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3924 | 回复: 0
打印 上一主题 下一主题

实例解读mysqldump参数--master-data [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-04 22:44 |只看该作者 |倒序浏览

实例解读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
后面紧接着就是file和position的记录,file和position记录的位置就是slave从master端复制文件的起始位置。默认情况下这个值是1
当这个值是2的时候,chang master to也是会写到dump文件里面去的,但是不会有上面那个作用了(thus is information only)
翻译过来真感觉拗口,呵呵,凑活看看吧。上实例!
一、先dump一个库
[root@HI0-OA-nagios ~]# mysqldump -uroot -pdfs123 --master-data=1 nagios > dumpfile
二、观察file和position的值,此时的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出来的文件,file和position的值和上面是相同的
[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
五、重启slave端mysql
Service mysql restart
六、此时netstat -an|grep 3306 看到slave和master的连接已经建立。现在不需要它们之间连接,登陆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


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/66227/showart_2111589.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP