第一部分:首先编译安装openssl
1.首先需要创建mysql用户
shell>groupadd mysql shell>useradd -s /sbin/nologin -g mysql mysql #设置mysql默认bash为nologin,不允许登录系统
2.依赖关系
shell>yum install ncurses shell>yum install ncurses-devel shell>yum install gcc libgcc gcc-c++ compat-gcc shell>yum install libtool libtool-ltdl-devel
3.编译安装openssl
shell>wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz shell>tar -zxvf openssl-1.0.1f.tar.gz shell>cd openssl-1.0.1f shell>./config -fPIC#不添加-fPIC参数,在make mysql阶段会报错 shell>make && make install #openssl默认安装位置在/usr/local/ssl
##error1
在编译openssl时
../include/violite.h:98:30: 错误:openssl/opensslv.h:没有那个文件或目录
../include/violite.h:114:25: 错误:openssl/ssl.h:没有那个文件或目录
../include/violite.h:115:25: 错误:openssl/err.h:没有那个文件或目录
In file included from libmysql.c:30:
../include/violite.h:127: 错误:expected specifier-qualifier-list before ‘SSL_CTX’
make[2]: *** [libmysql.lo] 错误 1
make[2]: Leaving directory `/root/nginx/mysql-5.5.3-m3/libmysql'
make[1]: *** [all] 错误 2
make[1]: Leaving directory `/root/nginx/mysql-5.5.3-m3/libmysql'
make: *** [all-recursive] 错误 1
解决:
shell>yum install openssl*
##error2
/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [openssl.so] Error 1
解决:
#重新编译openssl,加上-fPIC参数 shell>.config -fPIC
3./configure 参数配置
---------------------------------------------
#加载openssl路径
shell>LDFLAGS="-L/usr/local/ssl/lib" CFLAGS="-I/usr/local/ssl/include" CPPFLAGS="-I/usr/local/ssl/include" CXXFLAGS="-I/usr/local/ssl/include" #centos上测试不带这条也可以
#配置
shell>./configure --prefix=/usr/local/mysql --datadir=/data/mysql --with-charset=utf8 --with-extra-charsets=complex --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --with-pthread --with-ssl=/usr/local/ssl --enable-assembler --with-plugins=partition,archive,csv,federated,heap,innobase,myisam,myisammrg --with-mysqld-user=mysql
---------------------------------------------
##配置各项解释:
--prefix=/usr/local/mysql #基本安装目录
--datadir=/data/mysql #数据文件安装目录
--with-tcp-port=3306 #mysqld服务默认监听端口为3306,可以在这里指定一个端口
--with-charset=utf8 --with-extra-charsets=complex #字符编码设置
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock #mysql.sock用于服务器和客户机之间的通信,默认位置在/tmp/mysql.sock
--with-pthread --with-ssl=/usr/local/ssl #选择前一步骤中openssl的安装路径
--enable-assembler #To build the embedded MySQL library (libmysqld.a), use the
#--with-embedded-server option --with-plugins=partition,archive,csv,federated,heap,innobase,myisam,myisammrg --with-mysqld-user=mysql
4.编译安装
shell>make %% make install
5.安装后配置
##更改权限
shell>chown mysql.mysql /usr/local/mysql -R shell>chown mysql.mysql /data/mysql -R
##复制配置文件
shell>cd /home/mysql-5.1.70 shell>cp mysql-5.1.70/support-files/my-large.cnf /etc/my.cnf
##添加datadir
shell>vim /etc/my.cnf datadir=/data/mysql
#复制mysqld启动脚本
shell>cp mysql-5.1.70/support-files/mysql.server /etc/init.d/mysqld shell>chmod 755 /etc/init.d/mysqld
#初始化数据库
shell>/usr/local/mysql/bin/mysql_install_db --user=mysql
登录
shell>/usr/local/mysql/bin/mysql -uroot -p
修改密码
shell>/usr/local/mysql/bin/mysqladmin -u root password 'mysql'
5.添加ssl支持
shell>/usr/local/mysql/bin/mysql -uroot -p
#显示ssl状态
shell>show ariables like '%ssl%'; mysql> show variables like '%ssl%'; +---------------+----------+ | Variable_name | Value | +---------------+----------+ | have_openssl | DISABLED | | have_ssl | DISABLED | | ssl_ca | | | ssl_capath | | | ssl_cert | | | ssl_cipher | | | ssl_key | | +---------------+----------+
#启用ssl
shell>/etc/init.d/mysqld stop shell>vim /etc/my.cnf
#在[mysqld]下添加一行
ssl
#启动mysqld 再次查看
mysql> show variables like '%ssl%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | | | ssl_capath | | | ssl_cert | | | ssl_cipher | | | ssl_key | | +---------------+-------+
6.安装innodb_plugin 支持
#innodb_plugin 已经被内置在mysql安装目录下的/lib/mysql/plugin/中
#关闭mysqld
shell>/etc/init.d/mysqld stop
#编辑配置文件,添加下面几行
shell>vim /etc/my.cnf ignore_builtin_innodb plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
#重启mysqld
shell>/etc/init.d/mysqld restart shell>/usr/local/mysql/bin/mysql -uroot -p mysql> show plugins; +---------------------+----------+--------------------+---------------------+---------+ | Name | Status | Type | Library | License | +---------------------+----------+--------------------+---------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | partition | ACTIVE | STORAGE ENGINE | NULL | GPL | | ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL | | CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | | FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL | | MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL | | MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | InnoDB | ACTIVE | STORAGE ENGINE | ha_innodb_plugin.so | GPL | | INNODB_TRX | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMP | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | +---------------------+----------+--------------------+---------------------+---------+ 16 rows in set (0.00 sec)