脚踏实地、勇往直前!
全部博文(1005)
分类: Mysql/postgreSQL
2013-01-31 13:38:06
环境:
OS: Red Hat Linux As5
DB: 5.5.25
下面通过一个简单的例子说明下在mysql上配置复制的过程.
1.在master机器上修改my.cnf文件添加如下内容
[mysqld]
log-bin=master-bin
log-bin-index=master-bin.index
server-id=1
2.重启动master上的mysql服务
3.创建复制用户(master)
grant replication slave, replication client on *.* to repl@'192.168.0.%' identified by 'mysql';
4.将主库mysql目录下的data数据文件打包
mysql> FLUSH TABLES WITH READ LOCK;
shell> cd /usr/local/mysql/
shell> tar -cvf /tmp/mysql-snapshot.tar ./data
mysql> UNLOCK TABLES;
5.修改slave机器上的my.cnf文件添加如下内容
[mysqld]
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
6.将主库生成的tar文件拷贝拷贝到重库的data目录
7.找到master当前的logfile
mysql> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000002 | 1285 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
8. 若是slave已经启动的话,先停掉
stop slave;
下面将从file=master-bin.000002开始复制
9.在slave上连接master
change master to master_host='192.168.1.104',
master_port=3306,
master_user='repl',
master_password='mysql',
master_log_file='master-bin.000002',
master_log_pos=0;
10.启动slave
start slave
完成以上步骤后,在master上做的操作,将直接复制到slave.
11.查看从库的日志
mysql> SHOW SLAVE STATUS\G
-- The End --