# MySQL-5.7.20

Last edited by Junyangz AT 2018-05-18 19:40:27

## 准备安装包

> boost\_1\_59\_0.tar.gz cmake-2.8.12.tar.gz mysql-5.7.20.tar.gz

## 安装编译环境

```bash
yum install -y gcc gcc-c++ ncurses-devel perl
```

## 添加MySQL用户及用户组

```bash
groupadd mysql
useradd -r -g mysql mysql
mkdir /usr/local/mysql5.7
```

## 编译安装

```bash
tar zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boost

#cmake --version
tar zxvf cmake-2.8.12.tar.gz
cd cmake-2.8.12
./bootstrap
make && make install
cmake --version

cd ../
mkdir -p /usr/local/mysql-5.7.20
tar zxvf mysql-5.7.20.tar.gz
cd mysql-5.7.20
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.20 -DWITH_BOOST=/usr/local/boost/
make && make install

#unlink /usr/local/mysql
ln -s /usr/local/mysql-5.7 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql /usr/local/mysql-5.7
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
```

## 添加环境变量

```bash
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

source /etc/profile
#echo $MYSQL_HOME
mysql -V
```

## 配置启动

### 配置MySQL

```
#/etc/my.cnf
[mysql]
default-character-set = utf8
socket=/data2/mysql5.7/run/mysql.sock

[mysqld]
basedir=/usr/local/mysql
datadir=/data1/mysql5.7
user=mysql
symbolic-links=0
lower-case-table_names=1
socket=/data2/mysql5.7/run/mysql.sock
log-error=/data2/mysql5.7/log/mysqld.log
pid-file=/data2/mysql5.7/log/mysqld.pid
max-allowed-packet=32M
open-files-limit=65535

server-id = 20
log-bin = /data2/mysql5.7/log/mysql-bin
auto-increment-increment = 2
auto-increment-offset = 2
log-slave-updates = 1
relay-log = /data2/mysql5.7/log/relay-bin
relay-log-purge = 1
read_only=0
```

### 开机自启&初始化及启动

```bash
chkconfig mysqld on
chkconfig mysqld --list

service mysql start
mysqld --initialize-insecure --user=mysql  --datadir={$datadir}
# service mysql restart
```

## Reference

* [Installing MySQL from Source](https://dev.mysql.com/doc/refman/5.7/en/source-installation.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.junyangz.com/ops/mysql-5.7.20-crs2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
