本帖最后由 归一一 于 2012-11-25 18:51 编辑
MYSQL升级
之前从来没想过要更新数据库,平时用着挺稳定的。
前段时间看 很多说升级,升级特别快,也没什么感触。
直至前两天发现,不是最新版本很多功能没法用,比如分区。 正好要做主从备份。两台服务器要同版本;
目前版本:Server version: 5.0.95 需要升级到:5.5.28
系统是centos ,理论上 用 yum update mysql也可以, 但由于 yum源的问题。 只能更新到 5.0.95;
下面步骤 参考网址: http://mushme.iteye.com/blog/1631855
1、安装MySQL 5.5.x的yum源:
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
2、安装MySQL客户端的支持包:
yum install libmysqlclient15 --enablerepo=webtatic
3、卸载MySQL老版本的软件包:
---------------------------------------在这里 为了防止数据库数据丢失;要备份整个数据库;
yum remove mysql mysql-*
4、安装MySQL 5.5的客户端和服务端:
yum install mysql55 mysql55-server --enablerepo=webtatic
5、启动MySQL系统服务,更新数据库:
/etc/init.d/mysqld restart
mysql_upgrade
升级完毕
要备份整个数据库;
因为有很多数据库,不想一个个备份。一时没想太多,顺便熟悉下python ,下面把python 备份 每个数据库 脚本贴出来;移植性很方便。
#/home/guiyi/DataBaseDump.py
#Filename: DataBaseDump.py
#connectDB 数据库连接,ExportSData 数据库全部数据写入文件,DumpData 备份每个数据库
#This program is developped by Adair, [email protected]. Updated on 11, 13, 2012.
import MySQLdb;
import time;
import os,sys;
OutFile = open( "temp.log.txt","a"
;
os.system("screen"
;
def connectDB():
global conn, cursor
try:
conn = MySQLdb.connect(host='localhost',user='***',db='***',passwd='***');
except Exception, e:
print e
sys.exit()
cursor = conn.cursor();
def ExportSData():
global conn, cursor
connectDB()
OutFile.write(" start ExportData runing ..."+"\t" + time.asctime().replace(" ","."
+ "\n"
;
sql = "show databases;"
print sql;
cursor.execute(sql)
data = cursor.fetchall()
#print data;
outfile = open( "temp.S.file.txt","w"
;
for k in range(0,len(data)):
print data[k][0]
outfile.write(str(data[k][0])+"\n"
;
OutFile.write(" DoneExport-S-Dataruning ..."+"\t" + time.asctime().replace(" ","."
+ "\n"
;
outfile.close();
def DumpData():
global conn, cursor
connectDB()
dumpfile = open( "temp.dump.file.txt","w"
;
readfile = open( "temp.S.file.txt"
;
while 1:
line = readfile.readline();
num1 = line[0:50].strip();
#printnum1;
comm =" mysqldump -uroot -pjexresearch_pass "+ num1 + "|gzip>"+ num1 +".20121113.sql.gz";
print comm;
dumpfile.write(comm+"\n");
os.system(comm);
OutFile.write(" Done "+" comm"+"runing ..."+"\t" + time.asctime().replace(" ",".") + "\n");
if not line: break;
readfile.close();
dumpfile.close();
OutFile.close();
ExportSData();
DumpData();
|