最简单的MySQL replication配置过程.
环境:
系统: CentOS6.4
主机: master: 192.168.0.100 slave: 192.168.0.101
配置文件/etc/my.cnf修改前:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#
Disabling symbolic-links is recommended to prevent assorted security
risks
symbolic-links=0
0.备份配置文件:
cp /etc/my.cnf /etc/my.cnf.bk
1.改root密码
mysqladmin -u root password 123123
以上操作在master和slave上都执行一次.
2.master配置
1)修改/etc/my.cnf
[mysqld]之后添加
server-id=1
log-bin=mysql-bin
2)创建备份用户提供slave访问
mysql
-u root -p
GRANT replication SLAVE ON *.* TO ‘repl‘@‘192.168.0.1‘
IDENTIFIED BY ‘123123‘;
3)重启mysql服务
show master
status;如显示以下内容则master配置成功。(实际数据有差别)
+----------------------+-----------+--------------------+------------------------+
|
File
| Position | Binlog_Do_DB | Binlog_Ignore_DB
|
+----------------------+-----------+---------------------+-----------------------+
|
mysql-bin.000003 | 212 |
|
|
+----------------------+-----------+---------------------+------------------------+
记下File和Positon两列.配置slave会用到.
3.slave配置
1)修改/etc/my.cnf
[mysqld]之后添加
server-id=2
master-host=192.168.0.100
master-user=root
master-password=123123
master-port=3306
master-connect-retry=10
2)mysql配置
mysql
-u root -p
CHANGE MASTER TO
MASTER_HOST=‘192.168.0.100‘,MASTER_PORT=3306,MASTER_USER=‘repl‘,MASTER_PASSWORD=‘123123‘,MASTER_LOG_FILE=‘mysql- bin.000003‘,MASTER_LOG_POS=106;
(MASTER_LOG_FILE,MASTER_LOG_POS两列对应master的File,Positon两列)
3)重启mysql服务
4)启动slave
slave stop;
slave start;
show slave
status;查看slave是否正常运行.
show processlist \G;查看是否与master连接成功.
至此master上的修改会自动同步到slave.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。