文章目录
- @[toc]
- 环境情况
- 一些小问题记录
- 源码包怎么下载
- 二进制文件怎么下载
- CentOS 9 运行二进制文件会报错
- 编译 mysql
- 安装编译所需环境
- 安装 libtirpc-devel
- 没有安装 openssl-devel 的报错
- 没有安装 libtirpc-devel 的报错
- 没有安装 rpcgen 的报错
- cmake 编译
- MySQL cmake 一些常用的参数解释
- make 编译
- 验证 MySQL
文章目录
- @[toc]
- 环境情况
- 一些小问题记录
- 源码包怎么下载
- 二进制文件怎么下载
- CentOS 9 运行二进制文件会报错
- 编译 mysql
- 安装编译所需环境
- 安装 libtirpc-devel
- 没有安装 openssl-devel 的报错
- 没有安装 libtirpc-devel 的报错
- 没有安装 rpcgen 的报错
- cmake 编译
- MySQL cmake 一些常用的参数解释
- make 编译
- 验证 MySQL
环境情况
CentOS 9 下载地址
发行版
cat /etc/os-release
命令可以查看
VERSION="9"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="9"
PLATFORM_ID="platform:el9"
PRETTY_NAME="CentOS Stream 9"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:centos:centos:9"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
内核版本
uname -r
命令可以查看
5.14.0-210.el9.x86_64
一些小问题记录
源码包怎么下载
二进制文件怎么下载
CentOS 9 运行二进制文件会报错
- 二进制文件,有的环境执行会出现
error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
这样的报错- 这种都是缺少 lib 库造成的,可以使用 ldd 名称查看依赖
ldd mysql
可以看到
libtinfo.so.5 => not found
linux-vdso.so.1 (0x00007ffc92bf3000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc0a8e60000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fc0a8e5b000)
libcrypto.so.1.1 => /root/mysql-8.0.31-linux-glibc2.12-x86_64/bin/./../lib/private/libcrypto.so.1.1 (0x00007fc0a8800000)
libssl.so.1.1 => /root/mysql-8.0.31-linux-glibc2.12-x86_64/bin/./../lib/private/libssl.so.1.1 (0x00007fc0a8400000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fc0a8e47000)
librt.so.1 => /lib64/librt.so.1 (0x00007fc0a8e42000)
libtinfo.so.5 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc0a8000000)
libm.so.6 => /lib64/libm.so.6 (0x00007fc0a8d65000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc0a8d4a000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc0a7c00000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc0a8e6b000)
CentOS 9 现有的版本比 mysql 依赖的版本高,可以先通过 find 查找文件,然后软连接一下就好
find / -name "libtinfo.so.*"
主要看 lib64 这种目录
/var/tmp/dracut.5nyOQy/initramfs/usr/lib64/libtinfo.so.6.2
/var/tmp/dracut.5nyOQy/initramfs/usr/lib64/libtinfo.so.6
/var/tmp/dracut.BF9OGP/initramfs/usr/lib64/libtinfo.so.6.2
/var/tmp/dracut.BF9OGP/initramfs/usr/lib64/libtinfo.so.6
/var/tmp/dracut.GsBUVt/initramfs/usr/lib64/libtinfo.so.6.2
/var/tmp/dracut.GsBUVt/initramfs/usr/lib64/libtinfo.so.6
/var/tmp/dracut.udOLsV/initramfs/usr/lib64/libtinfo.so.6.2
/var/tmp/dracut.udOLsV/initramfs/usr/lib64/libtinfo.so.6
/usr/lib64/libtinfo.so.6
/usr/lib64/libtinfo.so.6.2
/usr/lib64/libtinfo.so.6
其实是一个软链接文件,实际的文件其实是/usr/lib64/libtinfo.so.6.2
- 新增一个软连接
ln -s /usr/lib64/libtinfo.so.6.2 /usr/lib64/libtinfo.so.5
再看一次
ldd mysql
,就都正常了
linux-vdso.so.1 (0x00007fff60d6d000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f59e9bda000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f59e9bd5000)
libcrypto.so.1.1 => /root/mysql-8.0.31-linux-glibc2.12-x86_64/bin/./../lib/private/libcrypto.so.1.1 (0x00007f59e9600000)
libssl.so.1.1 => /root/mysql-8.0.31-linux-glibc2.12-x86_64/bin/./../lib/private/libssl.so.1.1 (0x00007f59e9200000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f59e9bc1000)
librt.so.1 => /lib64/librt.so.1 (0x00007f59e9bbc000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f59e9b8b000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f59e8e00000)
libm.so.6 => /lib64/libm.so.6 (0x00007f59e9525000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f59e9b70000)
libc.so.6 => /lib64/libc.so.6 (0x00007f59e8a00000)
/lib64/ld-linux-x86-64.so.2 (0x00007f59e9be5000)
编译 mysql
编译的版本是
mysql-8.0.30
MySQL 下载地址
安装编译所需环境
yum -y install gcc gcc-c++ cmake ncurses ncurses-devel bison openssl-devel rpcgen
安装 libtirpc-devel
检查是否安装了
libtirpc
rpm -qa | grep libtirpc
如果没安装,执行
yum install -y libtirpc
如果安装了,根据版本到 清华源 搜索
libtirpc-devel
,之后执行下面的 rpm 命令,替换成对应版本的 url
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-1.el9.x86_64.rpm
没有安装 openssl-devel 的报错
Not a supported openssl version in WITH_SSL=system.
Make sure you have specified a supported SSL version.
Valid options are :
openssl[0-9]+ (use alternative system library)
yes (synonym for system)
</path/to/custom/openssl/installation>
CMake Error at cmake/ssl.cmake:83 (MESSAGE):
Please install the appropriate openssl developer package.
Call Stack (most recent call first):
cmake/ssl.cmake:379 (FATAL_SSL_NOT_FOUND_ERROR)
CMakeLists.txt:1768 (MYSQL_CHECK_SSL)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeError.log".
没有安装 libtirpc-devel 的报错
CMake Warning at cmake/rpc.cmake:40 (MESSAGE):
Cannot find RPC development libraries. You need to install the required
packages:
Debian/Ubuntu: apt install libtirpc-dev
RedHat/Fedora/Oracle Linux: yum install libtirpc-devel
SuSE: zypper install glibc-devel
Call Stack (most recent call first):
cmake/rpc.cmake:87 (WARN_MISSING_SYSTEM_TIRPC)
plugin/group_replication/libmysqlgcs/cmake/configure.cmake:34 (MYSQL_CHECK_RPC)
plugin/group_replication/libmysqlgcs/CMakeLists.txt:34 (INCLUDE)
CMake Error at cmake/rpc.cmake:88 (MESSAGE):
Could not find rpc/rpc.h in /usr/include or /usr/include/tirpc
Call Stack (most recent call first):
plugin/group_replication/libmysqlgcs/cmake/configure.cmake:34 (MYSQL_CHECK_RPC)
plugin/group_replication/libmysqlgcs/CMakeLists.txt:34 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeError.log".
没有安装 rpcgen 的报错
CMake Warning at cmake/rpc.cmake:29 (MESSAGE):
Cannot find rpcgen executable. You need to install the required packages:
Debian/Ubuntu: apt install rpcsvc-proto
RedHat/Fedora/Oracle Linux: yum install rpcgen
SuSE: zypper install glibc-devel
Call Stack (most recent call first):
plugin/group_replication/libmysqlgcs/cmake/rpcgen.cmake:112 (WARN_MISSING_RPCGEN_EXECUTABLE)
plugin/group_replication/libmysqlgcs/CMakeLists.txt:53 (INCLUDE)
CMake Error at plugin/group_replication/libmysqlgcs/cmake/rpcgen.cmake:113 (MESSAGE):
Could not find rpcgen
Call Stack (most recent call first):
plugin/group_replication/libmysqlgcs/CMakeLists.txt:53 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeError.log".
cmake 编译
MySQL cmake 一些常用的参数解释
-DCMAKE_INSTALL_PREFIX
-MySQL 的安装目录
-DMYSQL_USER
-MySQL 启动的用户名称,默认为 mysql
-DMYSQL_UNIX_ADDR
-Unix socket 文件路径
-DSYSCONFDIR
-配置文件目录
DSYSTEMD_PID_DIR
-PID 文件存储路径
-DDEFAULT_CHARSET
-默认字符集
-DDEFAULT_COLLATION
-校验字符
-DWITH_INNOBASE_STORAGE_ENGINE
-是否安装 innodb 存储引擎
-参数:1 or 0
-DWITH_ARCHIVE_STORAGE_ENGINE
-是否安装 archive 存储引擎
-参数:1 or 0
-DWITH_BLACKHOLE_STORAGE_ENGINE
-是否安装 blackhole 存储引擎
-参数:1 or 0
-DWITH_PERFSCHEMA_STORAGE_ENGINE
-是否安装 perfschema 存储引擎
-参数:1 or 0
-DMYSQL_DATADIR
-MySQL 数据存储路径
-DWITH_BOOST
-指定 boost 目录,需要下载的源码包包含 boost
-DFORCE_INSOURCE_BUILD
-强制编译,centos 9 版本不建议编译,所以需要加参数强行编译
-参数:1 or 0
-DWITH_SYSTEMD
-是否 systemctl 管理
-参数:1 or 0
-DMYSQL_TCP_PORT
-MySQL 默认端口
-DWITH_SSL
-是否支持 ssl
-参数:yes or no
-DENABLED_LOCAL_INFILE
-是否开启 load data infile 命令
-参数:1 or 0
开始编译
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=$(pwd)/boost/boost_1_77_0 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_SYSTEMD=1
没有
-DFORCE_INSOURCE_BUILD=1
参数会有如下报错
CMake Error at CMakeLists.txt:581 (MESSAGE):
Please do not build in-source. Out-of source builds are highly
recommended: you can have multiple builds for the same source, and there is
an easy way to do cleanup, simply remove the build directory (note that
'make clean' or 'make distclean' does *not* work)
You *can* force in-source build by invoking cmake with
-DFORCE_INSOURCE_BUILD=1
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.30/CMakeFiles/CMakeOutput.log".
如果在 cmake 的过程中有报错,当报错解决后,需要把源码目录中的 CMakeCache.txt 文件删除,然后再重新 cmake,不然还会报错
编译完成后会有类似如下的输出
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;RAPIDJSON_NO_SIZETYPEDEFINE;RAPIDJSON_SCHEMA_USE_INTERNALREGEX=0;RAPIDJSON_SCHEMA_USE_STDREGEX=1;HAVE_CONFIG_H;__STDC_LIMIT_MACROS;__STDC_FORMAT_MACROS;_USE_MATH_DEFINES;LZ4_DISABLE_DEPRECATE_WARNINGS;HAVE_TLSv13
-- CMAKE_C_FLAGS: -fno-omit-frame-pointer -ftls-model=initial-exec -O2 -g -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Wwrite-strings -Wjump-misses-init -Wstringop-truncation -Wmissing-include-dirs
-- CMAKE_CXX_FLAGS: -std=c++17 -fno-omit-frame-pointer -ftls-model=initial-exec -O2 -g -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Woverloaded-virtual -Wcast-qual -Wimplicit-fallthrough=5 -Wstringop-truncation -Wsuggest-override -Wmissing-include-dirs -Wextra-semi -Wlogical-op
-- CMAKE_CXX_FLAGS_DEBUG: -DSAFE_MUTEX -DENABLED_DEBUG_SYNC -g
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -g1
-- CMAKE_CXX_FLAGS_RELEASE: -ffunction-sections -fdata-sections -O3 -DNDEBUG
-- CMAKE_CXX_FLAGS_MINSIZEREL: -ffunction-sections -fdata-sections -Os -DNDEBUG
-- CMAKE_C_LINK_FLAGS:
-- CMAKE_CXX_LINK_FLAGS: -Wl,--copy-dt-needed-entries
-- CMAKE_EXE_LINKER_FLAGS
-- CMAKE_MODULE_LINKER_FLAGS
-- CMAKE_SHARED_LINKER_FLAGS
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mysql-8.0.30
make 编译
make -j <cpu核心数>
可以加快 make 的编译速度,当然,不要超过自己 cpu 的核心数,也要注意自己的 cpu 当前空闲的核心数,别把 cpu 当烧烤架了
make -j 3 && make install
编译完成后会有类似如下的输出
-- Installing: /usr/local/mysql/man/man1/comp_err.1
-- Installing: /usr/local/mysql/man/man1/ibd2sdi.1
-- Installing: /usr/local/mysql/man/man1/innochecksum.1
-- Installing: /usr/local/mysql/man/man1/lz4_decompress.1
-- Installing: /usr/local/mysql/man/man1/my_print_defaults.1
-- Installing: /usr/local/mysql/man/man1/myisam_ftdump.1
-- Installing: /usr/local/mysql/man/man1/myisamchk.1
-- Installing: /usr/local/mysql/man/man1/myisamlog.1
-- Installing: /usr/local/mysql/man/man1/myisampack.1
-- Installing: /usr/local/mysql/man/man1/mysql.1
-- Installing: /usr/local/mysql/man/man1/mysql_config.1
-- Installing: /usr/local/mysql/man/man1/mysql_config_editor.1
-- Installing: /usr/local/mysql/man/man1/mysql_secure_installation.1
-- Installing: /usr/local/mysql/man/man1/mysql_ssl_rsa_setup.1
-- Installing: /usr/local/mysql/man/man1/mysql_tzinfo_to_sql.1
-- Installing: /usr/local/mysql/man/man1/mysql_upgrade.1
-- Installing: /usr/local/mysql/man/man1/mysqladmin.1
-- Installing: /usr/local/mysql/man/man1/mysqlbinlog.1
-- Installing: /usr/local/mysql/man/man1/mysqlcheck.1
-- Installing: /usr/local/mysql/man/man1/mysqldump.1
-- Installing: /usr/local/mysql/man/man1/mysqldumpslow.1
-- Installing: /usr/local/mysql/man/man1/mysqlimport.1
-- Installing: /usr/local/mysql/man/man1/mysqlman.1
-- Installing: /usr/local/mysql/man/man1/mysqlpump.1
-- Installing: /usr/local/mysql/man/man1/mysqlshow.1
-- Installing: /usr/local/mysql/man/man1/mysqlslap.1
-- Installing: /usr/local/mysql/man/man1/perror.1
-- Installing: /usr/local/mysql/man/man1/zlib_decompress.1
-- Installing: /usr/local/mysql/man/man8/mysqld.8
-- Installing: /usr/local/mysql/man/man1/mysqlrouter.1
-- Installing: /usr/local/mysql/man/man1/mysqlrouter_passwd.1
-- Installing: /usr/local/mysql/man/man1/mysqlrouter_plugin_info.1
验证 MySQL
创建 mysql 用户,设置为不可登录
useradd mysql -s /sbin/nologin
修改目录权限
chown -R mysql.mysql /usr/local/mysql
创建配置文件
vim /etc/my.cnf
简单配置一个
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
port=3306
character_set_server=utf8
# lower_case_table_names 让MYSQL不区分表名大小写
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysql according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid
添加 MySQL 命令到 PATH 变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
MySQL 数据库初始化,这里使用的是无密码初始化,初始化完成后,会有如下警告:
[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysqld --initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
配置 systemctl 管理 MySQL
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
启动 MySQL 服务
systemctl daemon-reload
systemctl enable mysqld --now
进入 MySQL,因为是无密码,直接回车就可以进入 MySQL
mysql -uroot -p
修改 root 用户密码,同样因为是无密码,直接回车就可以了
mysqladmin -u root -p password '<这里改成自己需要设定的密码>'