秒杀MYSQL单双向同步_MySQL
bitsCN.com
简介 :
采用脚本直接配置,请事先安装好MYSQL,附件中脚本包里有4个文件分别为mysqlsa.py(主程序)、mysqldb(数据库模块)、master(参数)、slave(参数)
程序文件下载地址:http://down.51cto.com/data/229410
Sever info:
Master:192.168.1.3
Slave:192.168.1.4
脚本使用教程:
Master:192.168.1.3
1、解压TAR包
[root@SQL1 down]# tar -zxf mysql-master-slave.tar.gz
2、进入目录设置权限
[root@SQL1 down]# cd mysql-master-slave
[root@SQL1 mysql-master-slave]# chmod 777 mysqlsa.py
3、打开master文件,设置你需要同步的库
[root@SQL1 mysql-master-slave]# vi master
log-bin=/var/log/mysql/mysql-bin
binlog-ignore-db=mysql,test
binlog-do-db=wgdb
log-bin=/var/log/mysql/updatelog
4、运行脚本程序(这里注意如果你的MYSQL默认安装路经不是‘/usr/local/mysql'在此脚本程序的10~11行把成“export LD_LIBRARY_PATH=your path '你自己路经地址,否则有可能程序里面MySQLdb模块报错
[root@SQL1 mysql-master-slave]# ./mysqlsa.py
----------------------------------------------------------------------
1)Installation MySQL Master
2)Installation MySQL Slave
Q)Quit Installation
----------------------------------------------------------------------
Plase,Enter your option:
1:配置安装MYSQL主库
2:配置安装MYSQL从库
Q:退出
5、我们选择“1”配置MYSQL主库
[root@SQL1 mysql-master-slave]# ./mysqlsa.py
----------------------------------------------------------------------
1)Installation MySQL Master
2)Installation MySQL Slave
Q)Quit Installation
----------------------------------------------------------------------
Plase,Enter your option:1
6、提示要求输入SLAVE服务器IP,这步是创建访问帐号用的,我们输入SLAVE的IP:192.168.1.4,注意:千万别输错,不然SLAVE访问就会出错
Plase,Enter your option:1
Please,input your slave server ip:192.168.1.4
7、OK,执行完成以后程序不会给你任何提示!我们直接安Q退出,查看/etc/my.cnf的57行下面内容是否成功写入
54 # required unique id between 1 and 2^32 - 1
55 # defaults to 1 if master-host is not set
56 # but will not function as a master if omitted
57 server-id = 1
58 log-bin=/var/log/mysql/mysql-bin
59 binlog-ignore-db=mysql,test
60 binlog-do-db=wgdb
61 log-bin=/var/log/mysql/updatelog
8、重启MYSQL
[root@SQL1 down]# service mysqld restart
Slave:192.168.1.4
1、解压TAR包
[root@SQL2 down]# tar -zxf mysql-master-slave.tar.gz
2、进入目录设置权限
[root@SQL2 down]# cd mysql-master-slave
[root@SQL2 mysql-master-slave]#
3、打开slave文件,设置你需要同步的库和master的IP
master-host = 192.168.1.3
master-user = replication
master-password = *.asDICf.1KD
master-port = 3306
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
4、运行脚本程序(这里注意如果你的MYSQL默认安装路经不是‘/usr/local/mysql'在此脚本程序的10~11行把成“export LD_LIBRARY_PATH=your path '你自己路经地址,否则有可能程序里面MySQLdb模块报错
[root@SQL2 mysql-master-slave]# ./mysqlsa.py
----------------------------------------------------------------------
1)Installation MySQL Master
2)Installation MySQL Slave
Q)Quit Installation
----------------------------------------------------------------------
Plase,Enter your option:
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:
profile.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 > b:
#os.system('clear')
print '--' * 35
print '/t/t1)Installation MySQL Master/n'
print '/t/t2)Installation MySQL Slave/n'
print '/t/tQ)Quit Installation/n'
print '--' * 35
if ('err' in dir()) is True:
print err
del err
info = raw_input('/t/tPlase,Enter your option:')
if info.lower() == 'q':
sys.exit()
elif info == '1':
m.sql()
m.mk()
m.master()
m.re()
elif info == '2':
m.mk()
m.slave()
m.re()
else:
err ='/t/t***You enter the option error***'
本文出自 “Intelligence” 博客
bitsCN.com
핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Python은 다운로드한 파일을 열 수 있는 다음 옵션을 제공합니다: open() 함수: 지정된 경로와 모드(예: 'r', 'w', 'a')를 사용하여 파일을 엽니다. 요청 라이브러리: download() 메서드를 사용하여 자동으로 이름을 할당하고 파일을 직접 엽니다. Pathlib 라이브러리: write_bytes() 및 read_text() 메서드를 사용하여 파일 내용을 쓰고 읽습니다.

Go 언어는 효율적이고 간결하며 배우기 쉬운 프로그래밍 언어입니다. 동시 프로그래밍과 네트워크 프로그래밍의 장점 때문에 개발자들이 선호합니다. 실제 개발에서 데이터베이스 작업은 필수적인 부분입니다. 이 기사에서는 Go 언어를 사용하여 데이터베이스 추가, 삭제, 수정 및 쿼리 작업을 구현하는 방법을 소개합니다. Go 언어에서는 일반적으로 사용되는 SQL 패키지, Gorm 등과 같은 타사 라이브러리를 사용하여 데이터베이스를 운영합니다. 여기서는 sql 패키지를 예로 들어 데이터베이스의 추가, 삭제, 수정 및 쿼리 작업을 구현하는 방법을 소개합니다. MySQL 데이터베이스를 사용하고 있다고 가정합니다.

MySQLi를 사용하여 PHP에서 데이터베이스 연결을 설정하는 방법: MySQLi 확장 포함(require_once) 연결 함수 생성(functionconnect_to_db) 연결 함수 호출($conn=connect_to_db()) 쿼리 실행($result=$conn->query()) 닫기 연결( $conn->close())

Hibernate 다형성 매핑은 상속된 클래스를 데이터베이스에 매핑할 수 있으며 다음 매핑 유형을 제공합니다. Join-subclass: 상위 클래스의 모든 열을 포함하여 하위 클래스에 대한 별도의 테이블을 생성합니다. 클래스별 테이블: 하위 클래스별 열만 포함하는 하위 클래스에 대한 별도의 테이블을 만듭니다. Union-subclass: Joined-subclass와 유사하지만 상위 클래스 테이블이 모든 하위 클래스 열을 통합합니다.

Apple의 최신 iOS18, iPadOS18 및 macOS Sequoia 시스템 릴리스에는 사진 애플리케이션에 중요한 기능이 추가되었습니다. 이 기능은 사용자가 다양한 이유로 손실되거나 손상된 사진과 비디오를 쉽게 복구할 수 있도록 설계되었습니다. 새로운 기능에는 사진 앱의 도구 섹션에 '복구됨'이라는 앨범이 도입되었습니다. 이 앨범은 사용자가 기기에 사진 라이브러리에 포함되지 않은 사진이나 비디오를 가지고 있을 때 자동으로 나타납니다. "복구된" 앨범의 출현은 데이터베이스 손상으로 인해 손실된 사진과 비디오, 사진 라이브러리에 올바르게 저장되지 않은 카메라 응용 프로그램 또는 사진 라이브러리를 관리하는 타사 응용 프로그램에 대한 솔루션을 제공합니다. 사용자는 몇 가지 간단한 단계만 거치면 됩니다.

HTML은 데이터베이스를 직접 읽을 수 없지만 JavaScript 및 AJAX를 통해 읽을 수 있습니다. 단계에는 데이터베이스 연결 설정, 쿼리 보내기, 응답 처리 및 페이지 업데이트가 포함됩니다. 이 기사에서는 JavaScript, AJAX 및 PHP를 사용하여 MySQL 데이터베이스에서 데이터를 읽는 실제 예제를 제공하고 쿼리 결과를 HTML 페이지에 동적으로 표시하는 방법을 보여줍니다. 이 예제에서는 XMLHttpRequest를 사용하여 데이터베이스 연결을 설정하고 쿼리를 보내고 응답을 처리함으로써 페이지 요소에 데이터를 채우고 데이터베이스를 읽는 HTML 기능을 실현합니다.

MySQL 데이터베이스 관리 시스템의 기본 원리 분석 MySQL은 데이터 저장 및 관리를 위해 구조화된 쿼리 언어(SQL)를 사용하는 일반적으로 사용되는 관계형 데이터베이스 관리 시스템입니다. 이 글에서는 데이터베이스 생성, 데이터 테이블 설계, 데이터 추가, 삭제, 수정 및 쿼리 등을 포함한 MySQL 데이터베이스 관리 시스템의 기본 원리를 소개하고 구체적인 코드 예제를 제공합니다. 1. 데이터베이스 생성 MySQL에서는 먼저 데이터를 저장할 데이터베이스 인스턴스를 생성해야 합니다. 다음 코드는 "my

PHP는 웹사이트 개발에 널리 사용되는 백엔드 프로그래밍 언어로, 강력한 데이터베이스 운영 기능을 갖추고 있으며 MySQL과 같은 데이터베이스와 상호 작용하는 데 자주 사용됩니다. 그러나 한자 인코딩의 복잡성으로 인해 데이터베이스에서 잘못된 한자를 처리할 때 문제가 자주 발생합니다. 이 기사에서는 잘못된 문자의 일반적인 원인, 솔루션 및 특정 코드 예제를 포함하여 데이터베이스에서 중국어 잘못된 문자를 처리하기 위한 PHP의 기술과 사례를 소개합니다. 문자가 왜곡되는 일반적인 이유는 잘못된 데이터베이스 문자 집합 설정 때문입니다. 데이터베이스를 생성할 때 utf8 또는 u와 같은 올바른 문자 집합을 선택해야 합니다.
