作者:俊达
在大多数情况下,我们不需要自己编译MySQL源码,因为编译的MySQL和二进制包的内容基本一致。然而,有些特殊情况可能需要我们采用源码编译的方式安装MySQL:
因此,了解MySQL源码编译安装对于学习MySQL运维来说,确实是非常有帮助的。这不仅可以帮助我们更好地理解MySQL的工作原理,还可以让我们在面对一些特殊需求时,能够更加灵活地处理。
https://downloads.mysql.com/archives/community/
选择对应版本的源码包并下载
[root@box1 software]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.32.tar.gz --2021-03-29 05:50:54-- https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.32.tar.gz 正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14 正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Found 位置:https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.32.tar.gz [跟随至新的 URL] --2021-03-29 05:50:55-- https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.32.tar.gz 正在解析主机 cdn.mysql.com (cdn.mysql.com)... 184.27.193.3 正在连接 cdn.mysql.com (cdn.mysql.com)|184.27.193.3|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:52882168 (50M) [application/x-tar-gz] 正在保存至: “mysql-boost-5.7.32.tar.gz” 100%[================================================================================================================================================================================>] 52,882,168 2.76MB/s 用时 22s 2021-03-29 05:51:17 (2.32 MB/s) - 已保存 “mysql-boost-5.7.32.tar.gz” [52882168/52882168]) [root@box1 software]# md5sum mysql-boost-5.7.32.tar.gz fd78ae35fb019656a7a9cb5361e96201 mysql-boost-5.7.32.tar.gz
[root@box1 software]# tar xzf mysql-5.7.32.tar.gz [root@box1 software]# ls -l 总用量 54844 drwxr-xr-x. 35 7161 31415 4096 9月 23 2020 mysql-5.7.32 -rw-r--r--. 1 root root 56154080 3月 29 05:04 mysql-5.7.32.tar.gz
编译依赖条件
软件 |
---|
cmake |
make |
c/c++编译器 |
boost c++库 |
ssl库 |
编译选项
进入mysql源码目录
# cmake -L CMake Error at cmake/boost.cmake:88 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. -- Cache values CMAKE_BUILD_TYPE:STRING=RelWithDebInfo CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql COMMUNITY_BUILD:BOOL=ON DOWNLOAD_BOOST:BOOL=OFF DOWNLOAD_BOOST_TIMEOUT:STRING=600 ENABLED_PROFILING:BOOL=ON ENABLE_DTRACE:BOOL=ON ENABLE_GCOV:BOOL=OFF ENABLE_GPROF:BOOL=OFF ENABLE_MEMCACHED_SASL:BOOL=OFF ENABLE_MEMCACHED_SASL_PWDB:BOOL=OFF FEATURE_SET:STRING=community INSTALL_LAYOUT:STRING=STANDALONE MYSQL_DATADIR:PATH=/usr/local/mysql/data MYSQL_KEYRINGDIR:PATH=/usr/local/mysql/keyring OPTIMIZER_TRACE:BOOL=ON REPRODUCIBLE_BUILD:BOOL=OFF TMPDIR:PATH=P_tmpdir WITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON WITH_ASAN:BOOL=OFF WITH_ASAN_SCOPE:BOOL=OFF WITH_AUTHENTICATION_LDAP:BOOL=OFF WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON WITH_BOOST:PATH= WITH_CLIENT_PROTOCOL_TRACING:BOOL=ON WITH_DEBUG:BOOL=OFF WITH_DEFAULT_COMPILER_OPTIONS:BOOL=ON WITH_DEFAULT_FEATURE_SET:BOOL=ON WITH_EDITLINE:STRING=bundled WITH_EMBEDDED_SERVER:BOOL=ON WITH_EXTRA_CHARSETS:STRING=all WITH_FEDERATED_STORAGE_ENGINE:BOOL=ON WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON WITH_INNODB_MEMCACHED:BOOL=OFF WITH_LZ4:STRING=bundled WITH_MSAN:BOOL=OFF WITH_PARTITION_STORAGE_ENGINE:BOOL=ON WITH_RAPID:BOOL=ON WITH_SSL:STRING=system WITH_TEST_TRACE_PLUGIN:BOOL=OFF WITH_UBSAN:BOOL=OFF WITH_UNIT_TESTS:BOOL=ON WITH_VALGRIND:BOOL=OFF WITH_ZLIB:STRING=bundled
下载boost
下载 boost_1_59_0.tar.gz 解压 /root/software/boost_1_59_0
执行cmake
cmake . -DCMAKE_BUILD_TYPE=Debug \ -DMAKE_INSTALL_PREFIX=/app/dtstack/mysql \ -DCOMPILATION_COMMENT="lazybug" \ -DDEFAULT_CHARSET=utf8mb4 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_BOOST=/root/software/boost_1_59_0 \ -DWITH_SSL=system -- Running cmake version 2.8.12.2 -- Configuring with MAX_INDEXES = 64U -- CMAKE_GENERATOR: Unix Makefiles -- SIZEOF_VOIDP 8 -- MySQL 5.7.32 -- Packaging as: mysql-5.7.32-Linux-x86_64 -- Local boost dir /root/software/boost_1_59_0 -- Found /root/software/boost_1_59_0/boost/version.hpp -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900 -- BOOST_INCLUDE_DIR /root/software/boost_1_59_0 .... -- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -Werror -- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -Werror -- CMAKE_C_LINK_FLAGS: -- CMAKE_CXX_LINK_FLAGS: -- CMAKE_C_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC -DSAFE_MUTEX -- CMAKE_CXX_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC -DSAFE_MUTEX -- Configuring done -- Generating done -- Build files have been written to: /root/software/mysql-5.7.32
执行make
make -j 4 Scanning dependencies of target INFO_SRC Scanning dependencies of target INFO_BIN Scanning dependencies of target abi_check Scanning dependencies of target zlib [ 0%] Built target INFO_SRC [ 0%] [ 0%] Built target INFO_BIN [ 0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.o ... [100%] Building CXX object sql/CMakeFiles/mysqld.dir/main.cc.o Linking CXX executable mysqld [100%] Building CXX object storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/pfs_connect_attr-t.cc.o [100%] Building CXX object storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/__/__/__/sql/sql_builtin.cc.o [100%] 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 mysql_embedded [100%] Built target mysqltest_embedded [100%] Built target mysqld [100%] Built target pfs_connect_attr-t
执行make install 安装
root@box1 mysql-5.7.32]# make install [ 0%] Built target INFO_BIN [ 0%] Built target INFO_SRC [ 0%] Built target abi_check [ 0%] Built target zlib [ 2%] Built target edit ... -- Up-to-date: /usr/local/mysql/mysql-test/mysql-test-run -- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process -- Up-to-date: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process -- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/Base.pm -- Installing: /usr/local/mysql/support-files/mysqld_multi.server -- Installing: /usr/local/mysql/support-files/mysql-log-rotate -- Installing: /usr/local/mysql/support-files/magic -- Installing: /usr/local/mysql/share/aclocal/mysql.m4 -- Installing: /usr/local/mysql/support-files/mysql.server
安装的文件
[root@box1 mysql]# ls bin docs include lib LICENSE man mysql-test README README-test share support-files
目录 | 内容 |
---|---|
bin | mysql的可执行文件和工具,脚本 |
mysqld | |
mysql | |
mysqlbinlog | |
mysqldump | |
mysqladmin | |
mysqld_safe | |
docs | / |
include | 头文件,编译时依赖 |
lib | mysql client依赖库 |
mysql plugin | |
man | / |
share | mysql error信息 |
mysql系统初始化文件 | |
support | 一些脚本 |
初始化数据库和启动MySQL的步骤和上一篇二进制安装方式一样(MySQL运维实战(1.2)安装部署:使用二进制安装部署),这里不再重复。
更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw