安装环境准备
下载安装包
```
[root@wencq ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26.tar.gz
[root@wencq ~]# tar zxvf mysql-5.7.26.tar.gz
```
创建所需的安装目录/数据目录/socket文件目录
```
[root@wencq ~]# mkdir -p /app/mysql/{mysql-install,mysql-basedir,data,data1,tmp}
```
安装所需要的组件以及依赖环境
```
[root@wencq ~]#yum install -y cmake make bison bison-devel libaio-devel gcc gcc-c++ ncurses-devel
```
编译安装
添加编译参数
```
[root@wencq mysql-5.7.26]# cmake \
-DCMAKE_INSTALL_PREFIX=/app/mysql/mysql-install\
-DMYSQL_DATADIR=/app/mysql/data \
-DMYSQL_UNIX_ADDR=/app/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DSYSCONFDIR=/etc\
-DWITH_MEMORY_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
```
*** 报错:***
```
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:508 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/app/mysql-5.7.26/CMakeFiles/CMakeOutput.log".
See also "/app/mysql-5.7.26/CMakeFiles/CMakeError.log".
```
解决方法:
```
[root@wencq ~]#wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@wencq app]# tar zxvf boost_1_59_0.tar.gz -C /app/
[root@wencq app]# mv boost_1_59_0/ boost
[root@wencq mysql-5.7.26]# cmake \
-DCMAKE_INSTALL_PREFIX=/app/mysql/mysql-install\
-DMYSQL_DATADIR=/app/mysql/data \
-DMYSQL_UNIX_ADDR=/app/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DSYSCONFDIR=/etc\
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DWITH_BOOST=/app/boost \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
```
编译安装
```
[root@wencq mysql-5.7.26]# make && make install
```
安装收尾
授权mysql目录
```
[root@wencq app]# chown -R mysql.mysql /app/mysql
```
编辑主配置文件
```
[root@wencq data]# cat /etc/my.cnf
[mysqld]
basedir=/app/mysql/mysql-install
datadir=/app/mysql/data
socket=/app/mysql/tmp/mysql.sock
user=mysql
log_error=/tmp/mysql.log
skip_name_resolve
log_bin=/app/mysql/data/mysql-bin
server_id=5706
```
拷贝启动脚本
#### /etc/init.d
```
[root@wencq mysql-install]# cp -rp support-files/mysql.server /etc/init.d/
```
#### systemctl
```
[root@wencq bin]# vim /etc/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/mysql-install/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
```
目录授权并添加环境变量
```
[root@wencq bin]# echo "export PATH=$PATH:/app/mysql/mysql-install/bin">>/etc/profile
[root@wencq bin]# source /etc/profile
```
mysql初始化
```
[root@wencq data1]# /app/mysql/mysql-install/bin/mysqld --initialize-insecure --user=mysql --basedir=/app/mysql/mysql-basedir --datadir=/app/mysql/data1
```
启动mysql
```
[root@wencq data1]# systemctl start mysql
[root@wencq data1]# systemctl status mysql
● mysql.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysql.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-04-06 20:41:59 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 40365 (mysqld)
CGroup: /system.slice/mysql.service
└─40365 /app/mysql/mysql-install/bin/mysqld --defaults-file=/etc/my.cnf
Apr 06 20:41:59 wencq systemd[1]: Started MySQL Server.
[root@wencq data1]#
```