1.创建目录及用户

useradd mysql -s /sbin/nologin -M
mkdir /tools
mkdir /usr/local/mysql-5.7.20/{conf,tmp} -p
mkdir /data/mysql-5.7.20/data -p

2.下载软件

cd /tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
tar xf mysql-boost-5.7.20.tar.gz 
cd mysql-5.7.20

3.下载依赖

yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel autoconf* automake* zlib* libxml* ncurses-devel 
yum -y install ncurses libgcrypt* libtool* cmake openssl openssl-devel bison    bison-devel 
yum -y install imake perl-Data-Dumper libaio-devel boost boost-doc boost-devel
yum -y install ncurses5-devel  libxml2-devel expat-devel libaio bzr

4.编译

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.20 \
-DSYSCONFDIR=/usr/local/mysql-5.7.20/conf \
-DMYSQL_DATADIR=/data/mysql-5.7.20/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/tools/mysql-5.7.20/boost/boost_1_59_0 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.20/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DENABLE_DOWNLOADS=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_ZLIB:STRING=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \

#如果编译错误,有一个编译缓存文件需要删除
rm -f CMakeCache.txt

5.安装

make && make install

6.软连接

ln -s /usr/local/mysql-5.7.20  /usr/local/mysql

7.配置文件

cat >>/etc/my.cnf<

8.创建pid文件修改属主

mkdir /data/mysql/{data,tmp,log}
touch /data/mysql/mysqld.pid

chown -R mysql:mysql /data/mysql

9.初始化启动

#初始化
/usr/local/mysql/bin/mysqld  --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

#启动服务
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf  --user=mysql &

#查看初始密码登陆mysql(这个日志中记录了初始密码)
cat /data/mysql/log/error.log

mysql -uroot -p
密码:
mysql> set password for root@localhost = PASSWORD('123456');
mysql> flush privileges;