LNMP一键安装包mysql升级脚本

  1. 1. 升级脚本
  2. 2. Tips
  3. 3. 脚本下载

我是懒人,所以环境搭建直接用lnmp一键安装包,不过编译前稍微改过下那个脚本

lnmp已经提供了php和nginx的升级脚本,不过一直没提供mysql的升级脚本,今天突然来兴趣就写了个

我本地测试通过了,不过不能保证百分百能用,写的比较简单,其实就是把nginx的升级脚本拿来改的,容错性还不是很好

如果你想升级mysql,可以试用下,不过记得先备份var下的所有数据文件

另外,这个脚本仅针对从5.1.×升级到5.5.×,如果你是想在5.1.×里升级,那这个脚本不能用了

升级脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi

clear
echo "========================================================================="
echo "Upgrade Mysql for LNMP, Written by Licess"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo ""
echo "Upgrade Mysql tool Author:Joysboy"
echo "For more LNMP information please visit http://www.lnmp.org/"
echo "For more Upgrade Tool information please visit http://xfeng.me/"
echo "========================================================================="

nv=`mysql --version 2>&1`
old_mysql_version=`echo $nv | awk -F'[ ,]' '{print $6}'`
#echo $old_mysql_version

if [ "$1" != "--help" ]; then

#set mysql version

truemysql_version=""
trueecho "Current Nginx Version:$old_mysql_version"
trueecho "Please input mysql version you want:"
trueecho "Only for mysql version 5.5.*:"
trueecho "You can get version number from http://www.mysql.com/downloads/mysql/"
trueread -p "(example: 5.5.19 ):" mysql_version
trueif [ "$mysql_version" = "" ]; then
truetrueecho "Error: You must input mysql version!!"
truetrueexit 1
truefi
trueecho "==========================="

trueecho "You want to upgrade mysql version to $mysql_version"

trueecho "==========================="

trueget_char()
true{
trueSAVEDSTTY=`stty -g`
truestty -echo
truestty cbreak
truedd if=/dev/tty bs=1 count=1 2> /dev/null
truestty -raw
truestty echo
truestty $SAVEDSTTY
true}
trueecho ""
trueecho "Press any key to start...or Press Ctrl+c to cancel"
truechar=`get_char`

echo "============================check files=================================="
if [ -s mysql-$mysql_version.tar.gz ]; then
echo "mysql-$mysql_version.tar.gz [found]"
else
echo "Error: mysql-$mysql_version.tar.gz not found!!!download now......"
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-$mysql_version.tar.gz/from/http://mirror.services.wisc.edu/mysql/
dl_status=`echo $?`
if [ $dl_status = "0" ]; then
trueecho "Download mysql-$mysql_version.tar.gz successfully!"
else
trueecho "WARNING!May be the mysql version you input was wrong,please check!"
trueecho "Nginx Version input was:"$mysql_version
truesleep 5
trueexit 1
fi
fi

if [ -s /usr/local/bin/cmake -o -s /usr/bin/cmake ];then
echo "cmake [found]"
else
echo "Error: cmake not found!!! install now....."
wget -c http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
dl_status=`echo $?`
if [ $dl_status = "0" ]; then
trueecho "Download cmake-2.8.7.tar.gz successfully!"
truetar xvf cmake-2.8.7.tar.gz
truecd cmake-2.8.7/
true./configure
truegmake
truemake install
truecd ..
trueif [ -s /usr/bin/cmake ];then
truetrueecho "Install cmake successfully!"
trueelse
truetrueecho "Error install cmake..."
truetruesleep 5
truetrueexit 1
truefi
else
trueecho "Error download cmake-2.8.7.tar.gz"
truesleep 5
trueexit 1
fi
fi
echo "============================install mysql=================================="
rm -rf mysql-$mysql_version/

tar zxvf mysql-$mysql_version.tar.gz
cd mysql-$mysql_version/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
make

/etc/init.d/mysql stop
mv /usr/local/mysql/ /usr/local/mysql.old
make install
cp -a /usr/local/mysql.old/var/* /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data
chgrp -R mysql /usr/local/mysql/.
mv /etc/init.d/mysql /etc/init.d/mysql.old -f
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql

cat > /etc/ld.so.conf.d/mysql.conf< <EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig

rm -f /usr/lib/mysql
rm -f /usr/include/mysql
rm -f /usr/bin/mysql
rm -f /usr/bin/myisamchk
rm -f /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/lib /usr/lib/mysql
ln -s /usr/local/mysql/include /usr/include/mysql

/etc/init.d/mysql start
pid=`ps -ef|grep mysqld_safe|grep -v grep|awk '{print $2}'`
if [ "$pid" == "" ]; then
trueecho "Error Insatll Mysql...."
truecd ..
truesleep 5
trueexit 1
fi
echo "Upgrade completed!"
echo "Program will display Mysql Version......"
mysql --version
cd ../

echo "========================================================================="
echo "You have successfully upgrade from $old_mysql_version to $mysql_version"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo "========================================================================="
echo ""
echo "Upgrade Mysql tool Author:Joysboy"
echo "For more Upgrade Tool information please visit http://xfeng.me/"
echo "For more information please visit http://www.lnmp.org/"
echo ""
echo "========================================================================="
fi

Tips

这里需要提示几点,升级Mysql后需要重新编译PHP,否则没有对应的libmysqlclient.so

重新编译php很简单,运行一次LNMP提供的php升级脚本即可,如果不需要升级版本,输入相同版本号,升级前,如果你对php配置文件有过优化,记得备份php.ini

重新编译PHP后,如果你使用了eAccelerator,那么你还需要重新编译安装eAccelerator,这个也是直接运行LNMP的eAccelerator安装脚本即可

总之,没事别蛋疼升级mysql,会搞出一堆事情,后面有空我优化下脚本,升级mysql会一起吧php重新编译安装了

如果你不想使用我的脚本,自己编译升级的话,提示一点,cmake配置的时候不能少了-DDEFAULT_COLLATION=utf8_general_ci这个参数,否则启动检测字符集时会报错,无法启动,你只能重新编译一次

我第一次是把5.1.×的编译参数对照转换为5.5.×的参数,结果就少了这条,害我又编译一次

5.5.×和5.1.×编译参数对照表 CMake_Transition_Guide

脚本下载

本地下载: http://s.xfeng.me/A6Osgd
GitHub: http://s.xfeng.me/ACbZ0c

声明: 除非注明,小峰网络遨游记文章均为原创,转载请以链接形式标明本文地址

本博客原创文字只代表本人某一时间内的观点或结论,与本人所在公司没有任何关系。

本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。

第三方若用于商业用途的转载,须取得本人授权。

本文作者:

本文地址:http://xfeng.me/lnmp-upgrade-mysql-script/

你可能还对下面文章感兴趣: