秒杀MYSQL单双向同步(四)

2014-11-24 10:40:21 · 作者: · 浏览: 4
ile.write('export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/')

profile.close

else:

print 'Your mysql not installiation'

sys.exit(1)

class msa:

def sql(self):

try:

try:

conn = MySQLdb.connect(host = 'localhost',user='root',passwd='')

except:

pw = raw_input('Please,input your amdin of mysql passwd:')

conn = MySQLdb.connect(host = 'localhost',user='root',passwd='%s')%pw

IP = raw_input('Please,input your slave server ip:')

cursor = conn.cursor()

sql = "GRANT REPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO 'replication'@'%s' identified by '*.asDICf.1KD'; Flush privileges; "%(IP)

cursor.execute(sql)

except Exception,e:

print e

sys.exit()

def mk(self):

var='/var/log/mysql'

if not os.path.isdir(var):

os.makedirs(var)

os.chmod(var,448|56)

os.chown(var,500,500)

def master(self):

my_conf = open('/etc/my.cnf','r')

my_conf_read = my_conf.readlines()

my_conf.close

if re.search('binlog-do-db',str(my_conf_read)) is None:

master_file = open('master','r')

read = master_file.read()

my_conf_read.insert(57,read)

my_conf = open('/etc/my.cnf','w')

my_conf.writelines(my_conf_read)

master_file.close

my_conf.close

def slave(self):

my_conf = open('/etc/my.cnf','r')

my_conf_read = my_conf.readlines()

my_conf.close

if re.search('replicate-do-db',str(my_conf_read)) is None:

master_file = open('slave','r')

read = master_file.read()

my_conf_read.insert(57,read)

my_conf = open('/etc/my.cnf','w')

my_conf.writelines(my_conf_read)

master_file.close

def re(self):

my_conf = open('/etc/my.cnf','r')

#my_conf_read = my_conf.readlines()

my_conf.close

if info == '1':

= re.sub() = re.sub('log-bin=mysql-bin','#log-bin=mysql-bin',my_conf.read())

else:

if re.search('binlog-do-db',my_conf.read()) is None:

my_conf.seek(0)

= re.sub() = re.sub('server-id\t= 1\n','server-id\t= 2\n',my_conf.read())

else:

my_conf.seek(0)

= my_conf.read() = my_conf.read()

my_conf = open('/etc/my.cnf','w')

my_conf.writelines(sub)

my_conf.close

m = msa()

while 1