机器描述:
A机器 :10.8.3.240 B机器 :10.8.3.249
1、在两台机器上分别安装MySQL的客户端与服务端
rpm -ivh MySQL-server-5.5.16-1.rhel5.x86_64.rpm
rpm -ivh MySQL-client-5.5.16-1.rhel5.x86_64.rpm
2、修改配置文件
在两台机器把/usr/share/mysql/my-medium.cnf文件拷贝到 /etc下,并重命名为my.cnf
A机器修改如下:
server-id = 1
binlog-do-db = test
binlog-ignore-db = mysql
replicate-do-db = test
replicate-ignore-db = mysql
sync-binlog = 1
B机器修改如下:
server-id = 2
binlog-do-db = test
binlog-ignore-db = mysql
replicate-do-db = test
replicate-ignore-db = mysql
sync-binlog = 1
3、MySQL授权
在两台机器进入mysql后,执行以下命令,新增用户andy
GRANT ALL PRIVILEGES ON *.* TO 'andy'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'andy'@'localhost' IDENTIFIED BY '密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
4、在两台机器执行以下命令
STOP SLAVE; # A B 服务器停止同步
RESET MASTER; # A B 服务器清空MASTER日志
RESET SLAVE; # A B 服务器清空SLAVE日志
5、修改A服务器配置(修改为B服务器的主机状态)
CHANGE MASTER TO MASTER_HOST='10.8.3.249',MASTER_USER='andy', MASTER_PASSWORD='gaoxin',MASTER_LOG_FILE='binlog.000001',MASTER_LOG_POS=107;
6、修改B服务器配置(修改为A服务器的主机状态)
CHANGE MASTER TO MASTER_HOST='10.8.3.240',MASTER_USER='andy', MASTER_PASSWORD='gaoxin',MASTER_LOG_FILE='binlog.000001',MASTER_LOG_POS=107;
7、开启A B服务器同步进程
START SLAVE;
8、分别查看 A B服务器同步状态,确定是否成功
SHOW SLAVE STATUS;
SHOW MASTER STATUS;
9、重新执行以下三个命令:
slave stop;
reset slave;
slave start;
参考资料:http://blog.csdn.net/edwzhang/article/details/8819629
linux mysql卸载和重装
rpm -qa|grep -i mysql
rpm -e xxx