1. 安装依赖
yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
wget https://zh.osdn.net/projects/sfnet_boost/downloads/boost/1.59.0/boost_1_59_0.tar.gz/
2. 解压编译安装
[[email protected] ~]# tar xf mysql-5.7.20.tar.gz
[[email protected] ~]# mv boost_1_59_0.tar.gz mysql-5.7.20
[[email protected] ~]# cd mysql-5.7.20
[[email protected] mysql-5.7.20]# mkdir configure
[[email protected] mysql-5.7.20]# cd configure
[[email protected] configure]# cmake .. -DBUILD_CONFIG=mysql_release \
-DINSTALL_LAYOUT=STANDALONE \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_DTRACE=OFF \
-DWITH_EMBEDDED_SERVER=OFF \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_PAM=ON \
-DCMAKE_INSTALL_PREFIX=/var/mysql/ \
-DINSTALL_PLUGINDIR="/var/mysql/lib/plugin" \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EDITLINE=bundled \
-DFEATURE_SET=community \
-DCOMPILATION_COMMENT="MySQL Server (GPL)" \
-DWITH_DEBUG=OFF \
-DWITH_BOOST=..
[[email protected] configure]# make
[[email protected] configure]# make install # 此步骤很慢
3. 创建配置文件目录及用户
[[email protected] ~]# useradd -s /sbin/nologin mysql
[[email protected] ~]# mkdir -p /data/mysql
[[email protected] ~]# mkdir -p /var/mysql/log
[[email protected] ~]# chown -R mysql:mysql /data/mysql/
[[email protected] ~]# chown -R mysql:mysql /var/mysql/log
4. 修改配置文件
[[email protected] ~]# vim /etc/my.cnf
...
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
log_error=/var/mysql/log/error.log
basedir=/var/mysql
5. 初始化
[[email protected] ~]# /var/mysql/bin/mysqld --initialize --user=mysql
[[email protected] ~]# ll /data/mysql/
total 110628
-rw-r-----. 1 mysql mysql 56 Jul 10 17:51 auto.cnf
-rw-r-----. 1 mysql mysql 419 Jul 10 17:51 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Jul 10 17:51 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Jul 10 17:51 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Jul 10 17:51 ib_logfile1
drwxr-x---. 2 mysql mysql 4096 Jul 10 17:51 mysql
drwxr-x---. 2 mysql mysql 8192 Jul 10 17:51 performance_schema
drwxr-x---. 2 mysql mysql 8192 Jul 10 17:51 sys
[[email protected] ~]# ll /var/mysql/log/
total 4
-rw-r-----. 1 mysql mysql 802 Jul 10 17:51 error.log
6. 修改配置文件
[[email protected] ~]# cp /var/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# vim /etc/init.d/mysqld #找到如下两行
...
basedir=/var/mysql/
datadir=/data/mysql
...
[[email protected] ~]# mkdir -p /var/lib/mysql
[[email protected] ~]# chown -R mysql:mysql /var/lib/mysql
7. 添加环境变量
[[email protected] mysql]# vim /etc/profile
...
MYSQL_HOME=/var/mysql/bin/
PATH=$PATH:$MYSQL_HOME
[[email protected] ~]# source /etc/profile
8 . 修改原始密码
[[email protected] ~]# cat /var/mysql/log/error.log | grep generated
2018-07-10T09:51:31.365809Z 1 [Note] A temporary password is generated for [email protected]: pS:SCG1goPhj
[[email protected] ~]# /etc/init.d/mysqld start
[[email protected] ~]# ln -s /var/lib/mysql/mysql.sock /tmp/
[[email protected] ~]# mysql -uroot -p
密码为: pS:SCG1goPhj
mysql> alter user 'root'@'localhost' identified by '123123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
原文地址:http://blog.51cto.com/calabash/2140179