1.我的软件版本如下:

centos7编译安装 mysql 5.7.21_初始化

将其传入  /root目录下,

如图:

centos7编译安装 mysql 5.7.21_mysql5.7.21_02

2.卸载掉centos自带的mariadb

[root@yeshuai ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@yeshuai ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@yeshuai ~]# rpm -qa | grep mariadb
[root@yeshuai ~]#

3.解压boost压缩文件,并复制到/usr/local/下

[root@yeshuai ~]# tar zxvf  boost_1_59_0.tar.gz 
[root@yeshuai ~]# mv boost_1_59_0 /usr/local/boost
[root@yeshuai ~]# ll /usr/local/boost
总用量 108
drwxr-xr-x. 105 501 games 8192 8月 12 2015 boost
-rw-r--r--. 1 501 games 850 8月 11 2015 boost-build.jam
-rw-r--r--. 1 501 games 21920 8月 11 2015 boostcpp.jam
-rw-r--r--. 1 501 games 989 8月 11 2015 boost.css
-rw-r--r--. 1 501 games 6308 8月 11 2015 boost.png
-rw-r--r--. 1 501 games 2477 8月 11 2015 bootstrap.bat
-rwxr-xr-x. 1 501 games 10631 8月 11 2015 bootstrap.sh
drwx------. 7 501 games 84 8月 12 2015 doc
-rw-r--r--. 1 501 games 769 8月 11 2015 index.htm
-rw-r--r--. 1 501 games 5476 8月 11 2015 index.html
-rw-r--r--. 1 501 games 291 8月 11 2015 INSTALL
-rw-r--r--. 1 501 games 10779 8月 11 2015 Jamroot
drwx------. 116 501 games 4096 8月 12 2015 libs
-rw-r--r--. 1 501 games 1338 8月 11 2015 LICENSE_1_0.txt
drwxr-xr-x. 4 501 games 159 8月 11 2015 more
-rw-r--r--. 1 501 games 2608 8月 11 2015 rst.css
drwxr-xr-x. 2 501 games 141 8月 11 2015 status
drwxr-xr-x. 10 501 games 190 8月 11 2015 tools

4.安装相关依赖

yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison

5.创建mysql用户和组,以及相关文件夹

[root@yeshuai ~]#  groupadd mysql
[root@yeshuai ~]# useradd -g mysql mysql -s /sbin/nologin
[root@yeshuai ~]# mkdir -p /usr/local/mysql5
[root@yeshuai ~]# chown -R mysql:mysql /usr/local/mysql5
[root@yeshuai ~]# mkdir -p /data/mysql
[root@yeshuai ~]# chown -R mysql:mysql /data/mysql

6.解压mysql安装包,并用cmake编译

[root@yeshuai ~]# tar -xzf mysql-5.7.21.tar.gz 
[root@yeshuai ~]# cd mysql-5.7.21/
[root@yeshuai mysql-5.7.21]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5/ \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
> -DMYSQL_DATADIR=/data/mysql/ \
> -DSYSCONFDIR=/etc \
> -DMYSQL_USER=mysql \
> -DMYSQL_TCP_PORT=3306 \
> -DWITH_XTRADB_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_EXTRA_CHARSETS=1 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DWITH_BIG_TABLES=1 \
> -DWITH_DEBUG=0 \
> -DDOWNLOAD_BOOST=1 \
> -DWITH_BOOST=/usr/local/boost


............
............
............
[ 97%] Building CXX object sql/CMakeFiles/sql.dir/mysqld_daemon.cc.o
Linking CXX static library ../archive_output_directory/libsql.a
[100%] Built target sql
Scanning dependencies of target mysqld
Scanning dependencies of target pfs_connect_attr-t
[100%] Building CXX object sql/CMakeFiles/mysqld.dir/main.cc.o
Linking CXX executable mysqld
nnect_attr-t.cc.o
.o
Building C object storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/__/__/__/mysys/string.c.o
Linking CXX executable pfs_connect_attr-t
[100%] Built target mysqld
Scanning dependencies of target udf_example
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
[100%] Built target pfs_connect_attr-t
Linking CXX shared module udf_example.so
[100%] Built target udf_example


[root@yeshuai mysql5]# cd ~
[root@yeshuai ~]# ll
总用量 138304
-rw-------. 1 root root 1604 5月 26 19:28 anaconda-ks.cfg
-rw-r--r--. 1 root root 83709983 6月 9 11:01 boost_1_59_0.tar.gz
-rw-r--r--. 1 root root 6068021 6月 9 11:00 cmake-2.8.12.1.tar.gz
-rw-r--r--. 1 root root 1635 5月 27 11:08 initial-setup-ks.cfg
drwxr-xr-x. 38 7161 31415 4096 6月 25 16:29 mysql-5.7.21
-rw-r--r--. 1 root root 51822632 6月 9 11:00 mysql-5.7.21.tar.gz
drwxr-xr-x. 2 root root 6 6月 24 17:35 公共
drwxr-xr-x. 2 root root 6 6月 24 17:35 模板
drwxr-xr-x. 2 root root 6 6月 24 17:35 视频
drwxr-xr-x. 2 root root 6 6月 24 17:35 图片
drwxr-xr-x. 2 root root 6 6月 24 17:35 文档
drwxr-xr-x. 2 root root 6 6月 24 17:35 下载
drwxr-xr-x. 2 root root 6 6月 24 17:35 音乐
drwxr-xr-x. 2 root root 6 6月 24 17:35 桌面
[root@yeshuai ~]# cd mysql-5.7.21/
[root@yeshuai mysql-5.7.21]# make -j8


j8的含义是我笔记本有8个逻辑内核,如果你没有,可以输入top ,按1,看有几个内核

[root@yeshuai mysql-5.7.21]# make install
[ 0%] Built target INFO_BIN
[ 0%] Built target INFO_SRC
[ 0%] Built target abi_check
[ 0%] Built target zlib
[ 1%] Built target yassl
[ 2%] Built target taocrypt
[ 4%] Built target edit
[ 7%] Built target strings
[ 11%] Built target mysys
[ 11%] Built target dbug

centos7编译安装 mysql 5.7.21_mysql5.7.21_03

7.配置my.cnf,并初始化

[root@yeshuai rpm-common]# cp /root/mysql-5.7.21/packaging/rpm-common/my.cnf /etc/my.cnf
[root@yeshuai rpm-common]# vi /etc/my.cnf
[root@yeshuai rpm-common]# cat /etc/my.cnf
[root@yeshuai ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/tmp/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/data/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid



创建mysql.pid 的目录:
[root@yeshuai rpm-common]# mkdir -p /var/run/mysqld
[root@yeshuai rpm-common]# chown -R mysql:mysql /var/run/mysqld
初始化数据库:
[root@yeshuai mysql]# /usr/local/mysql5/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql5 --datadir=/data/mysql

查看日志,并找到初始化的密码:

[root@yeshuai mysql]# cat /data/mysql/mysqld.log 
tamp server option (see documentation for more details).
2022-06-25T10:50:24.841767Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-25T10:50:24.885817Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
s been started. Generating a new UUID: 9e37d084-f474-11ec-9df0-000c29c76855.
2022-06-25T10:50:24.951378Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-25T10:50:24.953658Z 1 [Note] A temporary password is generated for root@localhost: rYYD+)pmv4im

8.添加mysql系统启动脚本

[root@yeshuai mysql]# cp ~/mysql-5.7.21/support-files/mysql.server /etc/init.d/mysqld
[root@yeshuai mysql]# /etc/init.d/mysqld start
-bash: /etc/init.d/mysqld: 权限不够
[root@yeshuai mysql]# ll /etc/init.d/mysqld
-rw-r--r--. 1 root root 10571 6月 25 18:52 /etc/init.d/mysqld
[root@yeshuai mysql]# chmod 755 /etc/init.d/mysqld
[root@yeshuai mysql]# ll /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 10571 6月 25 18:52 /etc/init.d/mysqld
[root@yeshuai mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

9.将mysql添加进系统环境变量中

vim /etc/profile.d/mysql.sh

----------
export PATH=$PATH:/opt/mysql-5.7.21/bin


----------

source /etc/profile.d/mysql.sh

10.查看进程和端口号

centos7编译安装 mysql 5.7.21_mysql5.7.21_04

centos7编译安装 mysql 5.7.21_mysql5.7.21_05

结束!!!