MySQL8.0.40編譯安裝
近期MySQL發布了8.0.40版本,與之前的版本相比,部分依賴包發生了變化,因此重新編譯一版,也便于大家參考。
1. ?下載源碼
選擇對應的版本、選擇源碼、操作系統
如果沒有登錄或者沒有MySQL官網賬號,可以選擇只下載
2. ?進行編譯
上傳至機器,解壓源碼
tar -zxvf mysql-boost-8.0.40.tar.gz
2.1 ?準備階段
因為編譯安裝需要cmake、make等命令,因此需提前安裝相關依賴包及命令
yum install cmake make gcc gcc-c++ autoconf bison automake \
openssl openssl-devel zlib* fiex* libxml* \
ncurses-devel libmcrypt* libtool-ltdl-devel* -y
yum install gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binu
tils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc -y
由于MySQL從8.0.16版本開始,要求cmake的版本是cmake3以上,gcc版本為gcc 11.*以上版本,而且MySQL8.0.40的gcc需要12.*版本,因此如果使用Centos7等較低版本的操作系統,cmake及gcc ?g++版本較低,需要升級后才能編譯。相關包升級附在文末
創建相關目錄
mkdir /usr/local/mysql
mkdir -p /data/mysql/mysql3306/{data,logs,tmp,etc}
2.2 ?編譯檢查階段
開始編譯
cmake -DINSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/mysql3306/data \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql3306/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNODB_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all \
-DFORCE_INSPECT=1 \
-DCONNECT_WITH_SYSTEMD=OFF \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \
-DWITH_BOOST=/usr/local/mysql-8.0.40/boost/boost_1_77_0 \
-DENABLE_DOWNLOADS=1
出現報錯
-- Running cmake version 3.26.5
-- This is .el9. as found from 'rpm -qf /'
-- Looking for a devtoolset compiler
-- Using /opt/rh/gcc-toolset-12/root/usr/bin/gcc
-- Using /opt/rh/gcc-toolset-12/root/usr/bin/g++
-- CMAKE_MODULE_PATH is /usr/local/mysql-8.0.40/cmake
-- MySQL 8.0.40
-- The C compiler identification is GNU 12.2.1
-- The CXX compiler identification is GNU 12.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/rh/gcc-toolset-12/root/usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/rh/gcc-toolset-12/root/usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Source directory /usr/local/mysql-8.0.40
-- Binary directory /usr/local/mysql-8.0.40
CMake Error at CMakeLists.txt:642 (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
因此加上 ?-DFORCE_INSOURCE_BUILD=1 再編譯一次
cmake -DINSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/mysql3306/data \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql3306/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNODB_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all \
-DFORCE_INSPECT=1 \
-DCONNECT_WITH_SYSTEMD=OFF \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \
-DWITH_BOOST=/usr/local/mysql-8.0.40/boost/boost_1_77_0 \
-DENABLE_DOWNLOADS=1 \
-DFORCE_INSOURCE_BUILD=1
出現如下新報錯信息
CMake Error at cmake/readline.cmake:93 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:221 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:1929 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
缺少ncurses-devel依賴包所致,按照提示進行安裝
yum install -y ncurses-devel*
再次編譯出現新錯誤
缺少依賴,繼續補充
yum install libtirpc* -y
安裝后依舊報錯(因為我的操作系統yum安裝時沒有libtirpc-devel),因此我選擇查詢出源碼里的rpc.h文件,直接軟連接到 /usr/include/ ,不建議這么操作,如果可以下載對應的安裝包,建議安裝依賴包
?find?/?-name?rpc.h
/usr/local/mysql-8.0.40/extra/libevent/libevent-2.1.11-stable/include/event2/rpc.h
/usr/local/mysql-8.0.40/extra/tirpc/libtirpc-1.3.5/tirpc/rpc/rpc.h
/usr/local/mysql-8.0.40/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/windeps/sunrpc/rpc/rpc.h
ln?-s?/usr/local/mysql-8.0.40/extra/tirpc/libtirpc-1.3.5/tirpc/rpc/rpc.h???/usr/include/rpc/rpc.h
效果確實有效,繼續進行編譯,出現新問題:
CMake Warning at cmake/rpc.cmake:30 (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:113 (WARN_MISSING_RPCGEN_EXECUTABLE)
plugin/group_replication/libmysqlgcs/CMakeLists.txt:51 (INCLUDE)
CMake Error at plugin/group_replication/libmysqlgcs/cmake/rpcgen.cmake:114 (MESSAGE):
Could not find rpcgen
Call Stack (most recent call first):
plugin/group_replication/libmysqlgcs/CMakeLists.txt:51 (INCLUDE)
繼續安裝依賴包
yum install glibc-devel rpcgen -y
直至build完成
2.3? 進行編譯及安裝
開始make進行編譯,為了加快點速度,我啟用2個核心進行編譯
make -j 2
編譯過程中出現新問題???????
/usr/include/rpc/rpc.h:38:10: fatal error: rpc/types.h: No such file or directory
38 | #include <rpc/types.h> /* some typedefs */
| ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/build.make:99: plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/src/bindings/xcom/xcom/pax_msg.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:14468: plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target oci_common_objlib
make: *** [Makefile:166: all] Error 2
主要是前面的rpc依賴處理所致,因此將rpc目錄下所有文件都拷貝進來???????
cp -rp /usr/local/mysql-8.0.40/extra/tirpc/libtirpc-1.3.5/tirpc/rpc /usr/include/rpc
In file included from /usr/include/rpc/rpc.h:38,
from /usr/local/mysql-8.0.40/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/pax_msg.cc:28:
/usr/include/rpc/types.h:98:10: fatal error: netconfig.h: No such file or directory
98 | #include <netconfig.h>
| ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/build.make:99: plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/src/bindings/xcom/xcom/pax_msg.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:14468: plugin/group_replication/libmysqlgcs/CMakeFiles/mysqlgcs.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 15%] Linking CXX static library librpl_channel_credentials_lib.a
[ 15%] Built target rpl_channel_credentials_lib
make: *** [Makefile:166: all] Error 2
繼續復制依賴文件???????
完成后順利進行編譯。出現如下信息:
繼續進行make ?install
make install
完成后結果如下
編譯后MySQL內容如下
3. 安裝數據庫
創建數據庫相關目錄及配置文件
mkdir -p /data/mysql/mysql3306/{data,logs,tmp,etc}
配置文件按需添加放在etc/my.cnf中
創建mysql用戶并將數據庫目錄授權???????
useradd mysql
chown -R mysql:mysql /data/mysql/
初始化數據庫
cd /usr/local/mysql
bin/mysqld --defaults-file=/data/mysql/mysql3306/etc/my.cnf --initialize --user=mysql
如果無異常,則在數據庫日志中可以查看初始化的root@localhost賬號密碼
登錄數據庫并修改密碼
4. ?補充部分依賴安裝問題
4.1 cmake3
centos7系統中cmake預裝版本較低,而編譯8.0.40時需要更cmake3版本,如果無法通過yum install安裝時,需要自己下載安裝包進行安裝
例如我在Centos7系統上用的3.15.5版本,可以通過如下命令下載
wget https://down.24kplus.com/linux/cmake/cmake-3.15.5.tar.gz
再解壓、編譯、安裝即可
wget https://down.24kplus.com/linux/cmake/cmake-3.15.5.tar.gz
tar -zxvf cmake-3.15.5.tar.gz
cd cmake-3.15.5
./bootstrap --prefix=/usr --datadir=share/cmake --docdir=doc/cmake && make
make install
完成后檢查cmake版本
4.2 ?gcc
對于gcc版本,MySQL8.0.40之前gcc11即可,8.0.40版本開始需要gcc12,如果可以yum方式直接安裝比較方便,如果不能則需要臨時調整到高版本yum源進行安裝或下載安裝包進行安裝。本次使用的調整yum源的方式,步驟如下:???????
yum install scl-utils
yum install centos-release-scl centos-release-scl-rh
修改配置文件
vim /etc/yum.repos.d/CentOS-SCLo-scl.repo
添加如下內容
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/$basearch/sclo/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-testing]
name=CentOS-7 - SCLo sclo Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-source]
name=CentOS-7 - SCLo sclo Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/sclo/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-debuginfo]
name=CentOS-7 - SCLo sclo Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
再添加repo文件
vim /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
添加如下內容
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/$basearch/rh/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
重建yum元數據緩存???????
yum clean all
yum makecache
安裝gcc g++???????
yum install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils -y
4.3 libtirpc-devel
由于在Roky9上直接yum方式無libtirpc-devel包,因此手動下載安裝包進行安裝。需要用和libtirpc版本一致的,如果不一致,則缺少依賴。因此我直接將2個包都下載并安裝
wget http://rpmfind.net/linux/centos-stream/9-stream/BaseOS/x86_64/os/Packages/libtirpc-1.3.3-9.el9.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/CRB/x86_64/os/Packages/libtirpc-devel-1.3.3-6.el9.x86_64.rpm
再本地安裝???????
yum localinstall libtirpc-1.3.3-9.el9.x86_64.rpm
yum localinstall -y libtirpc-devel-1.3.3-9.el9.x86_64.rpm
4.4 重新構建及編譯
由于我在構建和編譯過程中有的包不存在或版本不對應,因此進行過一次重編譯,及cmake時添加fresh選項
cmake --fresh -DINSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/mysql3306/data \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql3306/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNODB_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all \
-DFORCE_INSPECT=1 \
-DCONNECT_WITH_SYSTEMD=OFF \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \
-DWITH_BOOST=/usr/local/mysql-8.0.40/boost/boost_1_77_0 \
-DENABLE_DOWNLOADS=1 \-DFORCE_INSOURCE_BUILD=1
???????