CentOS 7 编译安装 MySQL-5.7.9
本文主要来自https://typecodes.com/web/centos7compilemysql.html
实验环境
- VMware 12中最小化安装的CentOS 7 x64
- CentOS 7 配置为 2cpu 2G内存(原来分配1G,但是在编译MySQL到54%时卡住)
- 下载MySQL-5.7.9版本
配置防火墙和开放端口
以下操作在root用户中操作
[root@localhost ~]#systemctl stop firewalld.service #关闭防火墙
[root@localhost ~]#systemctl disable firewalld.service #禁止防火墙开机启动
[root@localhost ~]#vi /etc/selinux/config #关闭selinux
修改为SELINUX=disabled
[root@localhost ~]#setenforce 0 #使配置生效
[root@localhost ~]#yum install -y iptables-services #安装防火墙规则
[root@localhost ~]#vi /etc/sysconfig/iptables #配置防火墙规则
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT #添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT #添加
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
esc键,然后输入命令 :wq! 保存修改
[root@localhost ~]#systemctl restart iptables.service #重启防火墙使配置生效
[root@localhost ~]#systemctl enable iptables.service #设置防火墙开机启动
创建mysql用户和用户组
首先创建一个名为mysql且没有登录权限的用户和一个名为mysql的用户组
[root@localhost mysql]# groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql
下载编译MySQL5.7.9时需要的工具
######CMake编译工具
[root@localhost ~]# wget -c http://git.typecodes.com/libs/ccpp/cmake-3.2.1.tar.gz
[root@localhost ~]# tar -zxf cmake-3.2.1.tar.gz && cd cmake-3.2.1
[root@localhost cmake-3.2.1]# ./configure
[root@localhost cmake-3.2.1]# make && make install [默认安装路径是/usr/local/bin]
[root@localhost cmake-3.2.1]# cmake –version [查看cmake版本]
cmake version 3.2.1CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@localhost cmake-3.2.1]# cd ~ && rm -rf cmake-3.2.1*######Ncurses:提供功能键定义(快捷键),屏幕绘制以及基于文本终端的图形互动功能的动态库。
[root@localhost ~]# yum -y install ncurses-devel#######bison:GNU分析器生成器
[root@localhost ~]# wget -c http://git.typecodes.com/libs/ccpp/bison-3.0.tar.gz
[root@localhost ~]# tar -zxf bison-3.0.tar.gz && cd bison-3.0/ && ./configure
[root@localhost bison-3.0]# make && make install
[root@localhost bison-3.0]# cd ~ && rm -rf bison-3.0*#######Boost库:一个开源可移植的C++库,是C++标准化进程的开发引擎之一
下载 boost_1_59_0并上传到/root/目录(一定要这个版本以上,尝试多次安装1.57.0版本导致后面安装mysql5.7.9的时候会报找不到这个库的错误)
[root@typecodes ~]# tar -zxf boost_1_59_0.tar.gz && cd boost_1_59_0/
[root@localhost boost_1_59_0]# ./bootstrap.sh
[root@localhost boost_1_59_0]# ./b2 stage threading=multi link=shared
[root@localhost boost_1_59_0]# ./b2 install threading=multi link=shar