MySQL运维实战(1.3)安装部署:源码编译安装
源码编译安装
通常不需要自己编译mysql源码,编译的mysql和二进制包的内容基本一致。
当然有些时候可能会需要采用源码编译的方式安装,
安装一些非标准版本的mysql
安装一些社区的patch、bugfix、扩展插件
想禁用二进制版本编辑进去的某些特性
想使用二进制版本中没有编译进去的一些功能
想使用其他编译器或不同的编译器优化插件,如使用intel的c编译器
想链接一些其他基础库,如tcmalloc
编译debug版本的mysql,用来调试一些功能。
所以了解mysql源码编译安装,对学习mysql运维还是很有帮助的。
选择对应版本的源码包并下载
[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
2、解压代码
[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
3、编译安装
编译依赖条件
软件 | 说明 | |
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-files | 一些脚本 |
4、初始化数据库 & 启动MySQL
初始化数据库和启动MySQL的步骤和二进制安装方式一样,这里不再重复。