前言:
现时咱们对“源码安装mysql51”大约比较注重,看官们都想要剖析一些“源码安装mysql51”的相关文章。那么小编同时在网摘上网罗了一些关于“源码安装mysql51””的相关知识,希望咱们能喜欢,兄弟们快快来了解一下吧!作者:俊达
引言
在大多数情况下,我们不需要自己编译MySQL源码,因为编译的MySQL和二进制包的内容基本一致。然而,有些特殊情况可能需要我们采用源码编译的方式安装MySQL:
安装非标准版本的MySQL:有些特殊的应用场景会使用到MySQL的非标准版本,这时候我们就需要编译源码来安装。
安装社区的patch、bugfix、扩展插件:通过源码编译,可以轻松地添加社区提供的补丁、修复程序和扩展插件,以满足特定需求。
禁用二进制版本中的某些特性:源码编译可以让用户选择禁用或启用某些特定功能,以满足自己的需求。
使用未编译的功能:有些功能可能在二进制版本中并没有被编译进去,而通过源码编译可以启用这些功能。
使用其他编译器优化插件:源码编译可以让用户选择使用其他编译器进行编译,或者进行一些个性化的优化设置。例如,如果我们想要使用Intel的C编译器。
链接一些其他基础库:源码编译可以允许用户链接其他基础库,例如使用tcmalloc等。
编译debug版本:通过源码编译可以生成debug版本的MySQL,用于调试和分析问题。
因此,了解MySQL源码编译安装对于学习MySQL运维来说,确实是非常有帮助的。这不仅可以帮助我们更好地理解MySQL的工作原理,还可以让我们在面对一些特殊需求时,能够更加灵活地处理。
1 下载源码
MySQL :: Download MySQL Community Server (Archived Versions)
选择对应版本的源码包并下载
[root@box1 software]# wget 05:50:54-- 正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。已发出 HTTP 请求,正在等待回应... 302 Found位置: [跟随至新的 URL]--2021-03-29 05:50:55-- 正在解析主机 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 用时 22s2021-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.gzfd78ae35fb019656a7a9cb5361e96201 mysql-boost-5.7.32.tar.gz2 解压代码
[root@box1 software]# tar xzf mysql-5.7.32.tar.gz[root@box1 software]# ls -l总用量 54844drwxr-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.gz3 编译安装
编译依赖条件
软件
cmake
make
c/c++编译器
boost c++库
ssl库
编译选项
进入mysql源码目录
# cmake -LCMake 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 valuesCMAKE_BUILD_TYPE:STRING=RelWithDebInfoCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysqlCOMMUNITY_BUILD:BOOL=ONDOWNLOAD_BOOST:BOOL=OFFDOWNLOAD_BOOST_TIMEOUT:STRING=600ENABLED_PROFILING:BOOL=ONENABLE_DTRACE:BOOL=ONENABLE_GCOV:BOOL=OFFENABLE_GPROF:BOOL=OFFENABLE_MEMCACHED_SASL:BOOL=OFFENABLE_MEMCACHED_SASL_PWDB:BOOL=OFFFEATURE_SET:STRING=communityINSTALL_LAYOUT:STRING=STANDALONEMYSQL_DATADIR:PATH=/usr/local/mysql/dataMYSQL_KEYRINGDIR:PATH=/usr/local/mysql/keyringOPTIMIZER_TRACE:BOOL=ONREPRODUCIBLE_BUILD:BOOL=OFFTMPDIR:PATH=P_tmpdirWITH_ARCHIVE_STORAGE_ENGINE:BOOL=ONWITH_ASAN:BOOL=OFFWITH_ASAN_SCOPE:BOOL=OFFWITH_AUTHENTICATION_LDAP:BOOL=OFFWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ONWITH_BOOST:PATH=WITH_CLIENT_PROTOCOL_TRACING:BOOL=ONWITH_DEBUG:BOOL=OFFWITH_DEFAULT_COMPILER_OPTIONS:BOOL=ONWITH_DEFAULT_FEATURE_SET:BOOL=ONWITH_EDITLINE:STRING=bundledWITH_EMBEDDED_SERVER:BOOL=ONWITH_EXTRA_CHARSETS:STRING=allWITH_FEDERATED_STORAGE_ENGINE:BOOL=ONWITH_INNOBASE_STORAGE_ENGINE:BOOL=ONWITH_INNODB_MEMCACHED:BOOL=OFFWITH_LZ4:STRING=bundledWITH_MSAN:BOOL=OFFWITH_PARTITION_STORAGE_ENGINE:BOOL=ONWITH_RAPID:BOOL=ONWITH_SSL:STRING=systemWITH_TEST_TRACE_PLUGIN:BOOL=OFFWITH_UBSAN:BOOL=OFFWITH_UNIT_TESTS:BOOL=ONWITH_VALGRIND:BOOL=OFFWITH_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 4Scanning dependencies of target INFO_SRCScanning dependencies of target INFO_BINScanning dependencies of target abi_checkScanning 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.oLinking 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.oLinking 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]# lsbin 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
一些脚本
4 初始化数据库 & 启动MySQL
初始化数据库和启动MySQL的步骤和上一篇二进制安装方式一样(MySQL运维实战(1.2)安装部署:使用二进制安装部署),这里不再重复。
更多技术信息请查看云掣官网云掣YunChe - 可观测运维专家 | 大数据运维托管 | 云MSP服务
标签: #源码安装mysql51 #编译安装mysql51