5、我们选择‘2’安装从库
[root@SQL2 mysql-master-slave]# ./mysqlsa.py
----------------------------------------------------------------------
1)Installation MySQL Master
2)Installation MySQL Slave
Q)Quit Installation
----------------------------------------------------------------------
Plase,Enter your option:2
6、检查下‘/etc/my.cnf' 57行内容是否写入
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 2
master-host = 192.168.1.3
master-user = replication
master-password = *.asDICf.1KD
master-port = 3307
master-connect-retry = 60
replicate-ignore-db = mysql,test
replicate-do-db = wgdb
relay-log=/var/log/mysql/slave-relay-bin
slave-skip-errors=all
7、重起MYSQL
[root@SQL2 mysql-master-slave]# service mysqld restart
最后一步
1、进入Master 调整参数
[root@SQL1 down]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.57-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> slave stop;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| updatelog.000001 | 106 | wgdb | mysql,test |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
2、进入slave 调整参数
[root@SQL2 mysql-master-slave]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.57-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> slave stop;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000001',MASTER_LOG_POS=106;
Query OK, 0 rows affected (0.02 sec)
mysql> slave start;
Query OK, 0 rows affected (0.01 sec)
3、检查是否成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
以上配置已经全部完成,很多朋友可能会问,这只是单向同步吗?
答:只要把两个操作反向做下就OK
脚本程序问题在哪里?
答:http://down.51cto.com/data/229410
以下是主程序的代码
#!/usr/bin/python
#
#This is a mysql reversed sync and data pool script.
import os,MySQLdb
import sys
import re
#Check that Mysql exists
if os.path.isfile('/etc/my.cnf'):
b=os.system('python mysqldb.py')
profile = open('/etc/profile','r+')
if re.search('export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/',profile.read()) is None:
prof