1. 创建用户
useradd -M -s /sbin/nologin mysql
2. 创建目录
mkdir -p /data/my3306-5.7/mysql
mkdir -p /data/my3306-5.7/mysql/data
mkdir -p /data/my3306-5.7/mysql/tmp
mkdir -p /data/my3306-5.7/mysql/log/iblog
mkdir -p /data/my3306-5.7/mysql/log/binlog
mkdir -p /data/my3306-5.7/mysql/run
mkdir -p /usr/loacl/mysq-5.7
mkdir /tools
授权:
chown -R mysql:mysql /data/my3306-5.7
chown -R mysql:mysql /usr/loacl/mysq-5.7
3. 下载源码包
https://dev.mysql.com/downloads/mysql/
cd /tools
wget https://dev.mysql.com/downloads/file/?id=489854
4.下载boost软件
https://www.boost.org/users/history/
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download
5.解压
tar xf mysq-5.7.28.tar.gz
tar xf boost-1.59.0.tar.gz -C mysq-5.7.28
6. 安装cmake编译工具
yum install -y cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl autoconf
7.进行cmake编译mysql源文件
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7/ \
-DMYSQL_DATADIR=/data/my3306-5.7/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/data/my3306-5.7/mysql/run/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/data/my3306-5.7/mysql \
-DMYSQL_USER=mysql \
-DENABLE_DOWNLOADS=1 \
-DWITH_BOOST=/tools/mysql-5.7.26/boost \
-DWITH_READLINE=on
8.编译并安装
make & make install
9.编写配置文件
vim /data/my3306-5.7/mysql/my.cnf
[client]
#password = your_password
port = 3306
socket = /data/my3306-5.7/mysql/run/mysql.sock
default-character-set=utf8
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
### **character_set_server=utf8**
basedir=/usr/local/mysql-5.7/
datadir=/data/my3306-5.7/mysql/data
socket = /data/my3306-5.7/mysql/run/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
10.初始化数据库
./mysqld --defaults-file=/data/my3306-5.7/mysql/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql-5.7 --datadir=/data/my3306-5.7/mysql/data
11.开启服务并修改密码
/usr/local/mysql-5.7/support-files/mysql.server start
/usr/local/mysql-5.7/bin/mysqladmin -uroot -p password '123'
12.最终授权
chown -R mysql. /data/
chown -R mysql. /usr/local/mysql-5.*
13.查看默认配置文件读取顺序
/usr/local/mysql-5.6/bin/mysqld --verbose --help|grep -A 'Default options'