centos 7 MysSQL 5.7.23 源码安装

MySQL 5.7.23 源码安装

CentOS 7 将默认数据库MySQL替换成了Mariadb
这里会从系统的环境准备开始一步一步安装。

环境准备

系统版本 内核版本 IP地址
Centos 7.5 4.18.9-1.el7.elrepo.x86_64 10.0.0.3

备注 该系统采用MINI最小化安装,安装之后对系统进行了最基础的优化操作,操作过程点击这里

删除系统自带的依赖包

[root@node soft]# rpm -qa | egrep 'mysql|mariadb'
mariadb-libs-5.5.56-2.el7.x86_64
[root@node soft]# rpm -qa | egrep 'mysql|mariadb' | xargs rpm -e --nodeps
[root@node soft]# rpm -qa | egrep 'mysql|mariadb'
[root@node soft]# 

创建MySQL运行用户

[root@node soft]# useradd -s /sbin/nologin -M mysql
[root@node soft]# grep mysql /etc/passwd
mysql:x:1000:1000::/home/mysql:/sbin/nologin

下载 MySQL

可以在mirrors.163.com的163源下载
下载地址
如果上面的下载地址失效了,则可以使用百度网盘链接:https://pan.baidu.com/s/1hV30Sw2VY0PKgakVQcLoMw
提取码:qcao

[root@node soft]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23.tar.gz
--2018-10-08 11:03:26--  http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23.tar.gz
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 51907462 (50M) [application/octet-stream]
Saving to: ‘mysql-5.7.23.tar.gz’

100%[===================================================================================================================================================>] 51,907,462  1.67MB/s   in 30s    

2018-10-08 11:03:56 (1.65 MB/s) - ‘mysql-5.7.23.tar.gz’ saved [51907462/51907462]

[root@node soft]# ls
mysql-5.7.23.tar.gz
# 解压
[root@node soft]# tar xf mysql-5.7.23.tar.gz 
[root@node soft]# ls
mysql-5.7.23  mysql-5.7.23.tar.gz

编译安装

首先准备编译环境

使用yum下载编译工具和其他依赖包

[root@node soft]# yum install cmake bison git ncurses-devel gcc gcc-c++ -y

使用cmake编译工具对mysql进行编译

[root@node soft]# cd mysql-5.7.23
[root@node mysql-5.7.23]# pwd
/opt/soft/mysql-5.7.23
[root@node mysql-5.7.23]# ls
BUILD   CMakeLists.txt  configure.cmake  Docs                 include          libbinlogstandalone  libmysqld    mysql-test  packaging  README   sql         strings        unittest  win
client  cmd-line-utils  COPYING          Doxyfile-perfschema  INSTALL          libevent             libservices  mysys       plugin     regex    sql-common  support-files  VERSION   zlib
cmake   config.h.cmake  dbug             extra                libbinlogevents  libmysql             man          mysys_ssl   rapid      scripts  storage     testclients    vio
[root@node mysql-5.7.23]# cmake .  
-DCMAKE_INSTALL_PREFIX=/opt/mysql-5.7.23 
-DMYSQL_DATADIR=/opt/mysql-5.7.23/data 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DMYSQL_USER=mysql 
-DWITH_BOOST=/opt/soft/boost_1_59_0 
-DWITH_EMBEDDED_SERVER=OFF

-- Running cmake version 2.8.12.2
-- Configuring with MAX_INDEXES = 64U
-- CMAKE_GENERATOR: Unix Makefiles
-- SIZEOF_VOIDP 8
-- MySQL 5.7.23
-- Packaging as: mysql-5.7.23-Linux-x86_64
-- Downloading boost_1_59_0.tar.gz to /usr/local/boost
-- [download 100% complete]
-- [download 98% complete]
-- [download 100% complete]
-- [download 97% complete]
-- [download 100% complete]
-- [download 0% complete]
-- [download 1% complete]
-- [download 2% complete]
-- [download 3% complete]
-- [download 4% complete]
............................
# 一直到百分之百完成
-- Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an https proxy: export https_proxy=http://example.com:80
-- Performing Test HAVE_MISLEADING_INDENTATION
-- Performing Test HAVE_MISLEADING_INDENTATION - Failed
-- executable target mysqld debug_target /opt/soft/debug/sql/mysqld
-- INSTALL mysqlclient.pc lib/pkgconfig
-- Skipping deb packaging on unsupported platform .
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
-- CMAKE_C_LINK_FLAGS: 
-- CMAKE_CXX_LINK_FLAGS: 
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/soft/mysql-5.7.23
[root@node mysql-5.7.23]#

注:
DCMAKE_INSTALL_PREFIX=/usr/local/mysql:安装路径
DMYSQL_DATADIR=/data/mysql:数据文件存放位置
DSYSCONFDIR=/etc:my.cnf路径
DWITH_MYISAM_STORAGE_ENGINE=1:支持MyIASM引擎
DWITH_INNOBASE_STORAGE_ENGINE=1:支持InnoDB引擎
DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock:连接数据库socket路径
DMYSQL_TCP_PORT=3306:端口
DENABLED_LOCAL_INFILE=1:允许从本地导入数据
DWITH_PARTITION_STORAGE_ENGINE=1:安装支持数据库分区
DEXTRA_CHARSETS=all:安装所有的字符集
DDEFAULT_CHARSET=utf8:默认字符
DWITH_EMBEDDED_SERVER=1:嵌入式服务器

configuration完成之后,下面开始编辑安装

[root@node mysql-5.7.23]# make && make install
Scanning dependencies of target INFO_BIN
[  0%] Built target INFO_BIN
Scanning dependencies of target INFO_SRC
[  0%] Built target INFO_SRC
Scanning dependencies of target abi_check
[  0%] Built target abi_check
Scanning dependencies of target zlib
[  0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/compress.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/crc32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/deflate.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/gzio.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/infback.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inffast.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inflate.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inftrees.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/trees.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/uncompr.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/zutil.c.o
Linking C static library ../archive_output_directory/libzlib.a
[  0%] Built target zlib
Scanning dependencies of target yassl
[  0%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/buffer.cpp.o
[  0%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/cert_wrapper.cpp.o
[  0%] Building CXX object extra/yassl/CMakeFiles/
.............................
# 这里也是到百分之百后不报错,就结束啦。
-- Installing: /opt/mysql-5.7.23/mysql-test/./t/xa_prepared_binlog_off-master.opt
-- Installing: /opt/mysql-5.7.23/mysql-test/./t/xa_prepared_binlog_off.test
-- Installing: /opt/mysql-5.7.23/mysql-test/./t/xml.test
-- Installing: /opt/mysql-5.7.23/mysql-test/./valgrind.supp
-- Installing: /opt/mysql-5.7.23/mysql-test/./mtr
-- Installing: /opt/mysql-5.7.23/mysql-test/./mysql-test-run
-- Installing: /opt/mysql-5.7.23/mysql-test/./Makefile
-- Installing: /opt/mysql-5.7.23/mysql-test/./cmake_install.cmake
-- Installing: /opt/mysql-5.7.23/mysql-test/./CTestTestfile.cmake
-- Installing: /opt/mysql-5.7.23/./COPYING-test
-- Installing: /opt/mysql-5.7.23/./README-test
-- Up-to-date: /opt/mysql-5.7.23/mysql-test/mtr
-- Up-to-date: /opt/mysql-5.7.23/mysql-test/mysql-test-run
-- Installing: /opt/mysql-5.7.23/mysql-test/lib/My/SafeProcess/my_safe_process
-- Up-to-date: /opt/mysql-5.7.23/mysql-test/lib/My/SafeProcess/my_safe_process
-- Installing: /opt/mysql-5.7.23/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /opt/mysql-5.7.23/support-files/mysqld_multi.server
-- Installing: /opt/mysql-5.7.23/support-files/mysql-log-rotate
-- Installing: /opt/mysql-5.7.23/support-files/magic
-- Installing: /opt/mysql-5.7.23/share/aclocal/mysql.m4
-- Installing: /opt/mysql-5.7.23/support-files/mysql.server
[root@node mysql-5.7.23]# cd /opt/
[root@node opt]# ls
mysql-5.7.23  soft
[root@node opt]# cd mysql-5.7.23/
[root@node mysql-5.7.23]# ls
bin  COPYING  COPYING-test  docs  include  lib  man  mysql-test  README  README-test  share  support-files  usr

提示:
编译安装过程中,会有一些警告信息,可以忽略,只要不是error错误信息导致编译失败,就没啥问题。

配置环境变量

[root@node soft]# cd /opt/
[root@node opt]# ls
mysql-5.7.23  soft
[root@node opt]# chown -R mysql.mysql mysql-5.7.23
[root@node opt]# ll
total 0
drwxr-xr-x 9 mysql mysql 129 Sep 30 10:33 mysql-5.7.23
drwxr-xr-x 2 root  root   56 Sep 30 10:34 soft
[root@node opt]# echo 'export PATH=$PATH:/opt/mysql-5.7.23/bin' >> /etc/profile
[root@node opt]# tail -1 /etc/profile
export PATH=$PATH:/opt/mysql-5.7.23/bin
[root@node opt]# source /etc/profile
[root@node opt]# mysql -V
mysql  Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using  EditLine wrapper wrapper

配置文件

[root@node mysql-5.7.23]# cat my.cnf 
[client]
socket = /tmp/mysql.sock
port=3306

[mysql]
default-character-set=utf8

[mysqld]
basedir=/opt/mysql-5.7.23
datadir=/opt/mysql-5.7.23/data
port=3306
pid-file=/opt/mysql-5.7.23/mysqld.pid
skip-name-resolve
socket = /tmp/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /opt/mysql-5.7.23/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log = 80
flush_time = 0
join_buffer_size = 128M
max_allowed_packet = 1024M
max_connect_errors = 2000
open_files_limit = 4161
query_cache_type = 0
sort_buffer_size = 32M
table_definition_cache = 1400
binlog_row_event_max_size = 8K
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error = /opt/mysql-5.7.23/error.log
pid-file = /opt/mysql-5.7.23/mysqld.pid

初始化 MySQL

[root@node mysql-5.7.23]# pwd
/opt/mysql-5.7.23
[root@node mysql-5.7.23]# mkdir data
[root@node mysql-5.7.23]# ./bin/mysqld --initialize  --user=mysql --basedir=/opt/mysql-5.7.23 --datadir=/opt/mysql-5.7.23/data
2018-10-08T09:04:28.128022Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-10-08T09:04:28.359490Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-10-08T09:04:28.386577Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-10-08T09:04:28.445495Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 294d6e77-cad9-11e8-8795-000c2916c9b7.
2018-10-08T09:04:28.447604Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-10-08T09:04:28.449979Z 1 [Note] A temporary password is generated for root@localhost: %,K()<Y)p1W!

配置启动脚本并开机自启

[root@node mysql-5.7.23]# cp support-files/mysql.server /etc/init.d/mysqld
[root@node mysql-5.7.23]# chmod +x /etc/init.d/mysqld 
[root@node mysql-5.7.23]# chkconfig --add mysqld
[root@node mysql-5.7.23]# chkconfig  mysqld on
[root@node mysql-5.7.23]# chkconfig  | grep mysql

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@node mysql-5.7.23]# /etc/init.d/mysqld  start
Starting MySQL.. SUCCESS! 
[root@node mysql-5.7.23]# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.23 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> q
Bye

查看日志

[root@node mysql-5.7.23]# cat error.log 
2018-10-08T09:06:22.978084Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-10-08T09:06:22.978123Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-10-08T09:06:22.978145Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-10-08T09:06:22.978165Z 0 [Note] /opt/mysql-5.7.23/bin/mysqld (mysqld 5.7.23) starting as process 85884 ...
2018-10-08T09:06:23.012316Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-10-08T09:06:23.012531Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-10-08T09:06:23.012541Z 0 [Note] InnoDB: Uses event mutexes
2018-10-08T09:06:23.012544Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-10-08T09:06:23.012547Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-10-08T09:06:23.012567Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB
2018-10-08T09:06:23.013278Z 0 [Note] InnoDB: Number of pools: 1
2018-10-08T09:06:23.013357Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-10-08T09:06:23.014423Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-10-08T09:06:23.027048Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-10-08T09:06:23.029941Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-10-08T09:06:23.042131Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-10-08T09:06:23.048764Z 0 [Warning] InnoDB: Resizing redo log from 2*3072 to 2*8192 pages, LSN=2588953
2018-10-08T09:06:23.152042Z 0 [Warning] InnoDB: Starting to delete and rewrite log files.
2018-10-08T09:06:23.183822Z 0 [Note] InnoDB: Setting log file ./ib_logfile101 size to 128 MB
2018-10-08T09:06:23.183932Z 0 [Note] InnoDB: Progress in MB:
 100
2018-10-08T09:06:23.322038Z 0 [Note] InnoDB: Setting log file ./ib_logfile1 size to 128 MB
2018-10-08T09:06:23.322150Z 0 [Note] InnoDB: Progress in MB:
 100
2018-10-08T09:06:23.462641Z 0 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-10-08T09:06:23.462689Z 0 [Warning] InnoDB: New log files created, LSN=2588953
2018-10-08T09:06:23.462962Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-10-08T09:06:23.463003Z 0 [Note] InnoDB: Setting file '/opt/mysql-5.7.23/data/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-10-08T09:06:23.475948Z 0 [Note] InnoDB: File '/opt/mysql-5.7.23/data/ibtmp1' size is now 12 MB.
2018-10-08T09:06:23.476603Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-10-08T09:06:23.476611Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-10-08T09:06:23.476865Z 0 [Note] InnoDB: Waiting for purge to start
2018-10-08T09:06:23.527970Z 0 [Note] InnoDB: 5.7.23 started; log sequence number 2588944
2018-10-08T09:06:23.528861Z 0 [Note] Plugin 'FEDERATED' is disabled.
2018-10-08T09:06:23.546917Z 0 [Note] InnoDB: Loading buffer pool(s) from /opt/mysql-5.7.23/data/ib_buffer_pool
2018-10-08T09:06:23.551708Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181008 17:06:23
2018-10-08T09:06:23.552223Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-10-08T09:06:23.552261Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2018-10-08T09:06:23.552568Z 0 [Note] IPv6 is available.
2018-10-08T09:06:23.552770Z 0 [Note]   - '::' resolves to '::';
2018-10-08T09:06:23.553044Z 0 [Note] Server socket created on IP: '::'.
2018-10-08T09:06:23.581116Z 0 [Note] /opt/mysql-5.7.23/bin/mysqld: ready for connections.
Version: '5.7.23'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

原文地址:https://www.cnblogs.com/winstom/p/9755487.html