由于MySQL从5.5之后的版本源码编译安装用cmake, make, make install安装,不用./Configure,make,make install 安装,所以要看下系统是不是有cmake这个命令,红帽企业版5默认是没有安装的,所以要手动安装(红帽6已默认安装)。cmake安装方法在网上搜下就行。
安装Mysql官方给的方法如下:
# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> cmake .
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
自己编译的时候后面加了参数:
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
在执行make时编译失败:
[ 69%] Building C object vio/CMakeFiles/vio.dir/viossl.c.o
/root/mysql-5.5.42/vio/viossl.c: In function assl_doa:
/root/mysql-5.5.42/vio/viossl.c:175: error: aSSL_OP_NO_COMPRESSIONa undeclared (first use in this function)
/root/mysql-5.5.42/vio/viossl.c:175: error: (Each undeclared identifier is reported only once
/root/mysql-5.5.42/vio/viossl.c:175: error: for each function it appears in.)
make[2]: *** [vio/CMakeFiles/vio.dir/viossl.c.o] Error 1
make[1]: *** [vio/CMakeFiles/vio.dir/all] Error 2
make: *** [all] Error 2
这个为openssl版本太低的原因,mysql5.5无法在openssl-1.0.0及更低版本下编译导致的。查看了下openssl的版本为openssl-0.9.8,openssl version -a.
如果不需要ssl可以去掉WITH_SSL配置项,也可以升级openssl的版本,另外更方便的方法可以在cmake之前打一个补丁。
升级openssl:
从ftp://ftp.openssl.org/source/下载
tar -xvf openssl-1.0.2a.tar.gz
cd openssl-1.0.2a
./config shared zlib
make
make install
mv /usr/bin/openssl /tmp/
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -v | grep openssl
查看版本:
openssl version -a
重新编译:
先执行:
make clean
rm CMakeCache.txt
然后重头再来,发现还是不成功(升级后还不成功到底啥原因呢?)。最后把-DWITH_SSL=system 这项去掉编译成功。
下面为去掉DWITH_SSL=system的参数:
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci