5)cmake后在下面這個路徑的這個文件CMakeLists.txt增加如下這部分字段
1.軟件介紹
MySQL 是一個關系型數據庫管理系統。
本文以 MySQL 5.7.30 版本
虛擬服務器 KVM Virtual Machine
虛擬機配置:32G內存,8核 aarch64架構 virt-rhel7.6.0 300G磁盤空間
虛擬機操作系統:Linux version 4.19.0-arm64-server (deepin@deepin-PC) (gcc version 8.3.0 (Debian 8.3.0-6))
3.支持的操作系統
UOS : Linux version 4.19.0-arm64-server (deepin@deepin-PC) (gcc version 8.3.0 (Debian 8.3.0-6))
4.使用版本和獲取方式
mysql-5.7.30.tar.gz
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.30.tar.gz
mysql-boost-5.7.30.tar.gz
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.30.tar.gz
安裝包放在/home/demo/tools/
5.編譯和測試方式
1)添加apt-get 安裝源
vi /etc/apt/sources.list
輸入
## Generated by deepin-installer
deb [by-hash=force] https://packages.chinauos.cn/uos eagle main contrib non-free
#deb-src https://packages.chinauos.cn/uos eagle main contrib non-free
deb http://ftp.cn.debian.org/debian stretch main
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
關閉保存
2)安裝相關編譯包
sudo apt-get update
sudo apt-get install -y cmake
sudo apt-get install -y git
sudo apt-get install -y build-essential
sudo apt-get install -y openssl
sudo apt-get install -y libssl-doc(這個可能不需要裝)
sudo apt-get install aptitude
aptitude安裝不上的話 刷新下源
apt-get update
apt-get dist-upgrade
sudo aptitude install -y libssl-dev
sudo aptitude install -y libncurses5-dev
sudo aptitude install -y libncurses5
sudo aptitude install -y pkg-config
sudo aptitude install -y bison
sudo aptitude install -y libtirpc1
sudo aptitude install -y libtirpc-dev
sudo apt-get install -y chkconfig
3)解壓mysql
mkdir -p /home/demo/tools/
cd /home/demo/tools/
tar zxvf mysql-5.7.30.tar.gz
tar zxvf mysql-boost-5.7.30.tar.gz
4)配置cmake編譯及相關參數
cd mysql-5.7.30/
vi CMakeLists.txt
在文件開頭
option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIC})
保存CMakeLists.txt
cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
5)cmake后在下面這個路徑的這個文件CMakeLists.txt增加如下這部分字段
vi /home/demo/tools/mysql-5.7.30/storage/innobase/CMakeLists.txt
fts/fts0fts.cc
handler/handler0alter.cc
row/row0mysql.cc
srv/srv0srv.cc
在這個文件 /home/demo/tools/mysql-5.7.30/sql/mysqld.cc 注釋掉
6)獲取服務器CPU核心數
cat /proc/cpuinfo | grep processor |wc -l
執行make編譯 此處的8是上面CPU核心數命令的返回值 代表用幾核編譯 提高速度
make -j 8 && make install
7)遇到的報錯的處理
20%] Built target mysys_ssl
[ 20%] Building C object extra/CMakeFiles/comp_err.dir/comp_err.c.o
[ 20%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_message.cc.o
[ 20%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_message_fiel
[ 20%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_name_resolve
[ 20%] Linking CXX executable comp_err
/usr/bin/ld: CMakeFiles/comp_err.dir/comp_err.c.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which maused when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/comp_err.dir/comp_err.c.o(.text+0x7c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `std
/usr/bin/ld: 最后的鏈結失敗: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [extra/CMakeFiles/comp_err.dir/build.make:105:extra/comp_err] 錯誤 1
make[1]: *** [CMakeFiles/Makefile2:6738:extra/CMakeFiles/comp_err.dir/all] 錯誤 2
make[1]: *** 正在等待未完成的任務....
解決:
CMakeLists.txt 是mysql源碼根目錄下的
vi CMakeLists.txt文件開頭 option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE)set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIC})