参考:https://www.veryarm.com/113426.html
1、平台:
1. ubuntu 16.04 86bit
2. arm: ARM aarch64
3. mysql 5.7.25,tar.gz 下载链接:http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.7/
2、编译依赖库ncurses-6.1.tar.gz
1. 下载:https://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
解压:tar -zxvf ncurses-6.1.tar.gz
进到ncurses-6.1目录
2. 配置:
./configure --prefix=/usr/local/ncurses --host=aarch64-poky-linux CFLAGS="--sysroot=$SDKTARGETSYSROOT" --without-progs
注意:若不加 --without-progs 将会出现以下错误
3. 编译:make
4. 安装:make install
3.交叉编译boost_1_59_0
1. 编译器:aarch64-poky-linux-gcc
2. 下载源码包boost_1_67_0.tar.gz
3. 解压后进入目录。
4. 执行 sudo ./bootstrap.sh --prefix=/home/arm/boost167
5. 生成有 b2 和 bjam ,project-config.jam 的文件
6. 修改project-config.jam该文件的一行(指定自己的编译器):
using gcc : : /opt/fsl-imx-xwayland/4.14-sumo/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux ;
注意空格。
7. 编译 sudo ./b2
8. 安装 sudo ./b2 install
4.编译PC版
1. 解压mysql 5.7.25.tar.gz到opt/目录下。并改名为mysql 5.7.25-pc
2. 进入mysql 5.7.25-pc目录执行以下:
cmake . -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost_1_59_0 -DCMAKE_INSTALL_PREFIX=${PWD}/out
5.编译ARM版
1. 解压mysql 5.7.25.tar.gz到opt/目录下。并改名为mysql 5.7.25-arm
2. 进入mysql 5.7.25-arm目录下,新建文件imx.cmake,并打开输入以下配置:
################################################
####### General crosscompile toolchain file
################################################
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)
SET(CMAKE_SYSROOT /opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux)
SET(CMAKE_FIND_ROOT_PATH /opt/fsl-imx-xwayland/4.14-sumo)
SET(CMAKE_C_COMPILER ${CC})
SET(CMAKE_CXX_COMPILER ${CXX})
SET(CMAKE_C_COMPILER_ARG1 "-march=ARCH -mfpu=neon -mfloat-abi=hard -mcpu=CPU --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux")
SET(CMAKE_CXX_COMPILER_ARG1 "-march=ARCH -mfpu=neon -mfloat-abi=hard -mcpu=CPU --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux")
set(LOCAL_BOOST_DIR /usr/local/boost/boost_1_59_0)
set(BOOST_INCLUDE_DIR /usr/local/boost/boost_1_59_0/include)
set(BOOST_LIBRARY_DIR /usr/local/boost/boost_1_59_0/lib)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
################################################################
####### The special configuration MACRO for mysql
################################################################
SET(WITH_UNIT_TESTS OFF) ## disable unit_test
SET(DEFAULT_CHARSET utf8) ## the default charset
SET(DEFAULT_COLLATION utf8_general_ci)
SET(EXTRA_CHARSETS all) ## Which extra character sets to include:
SET(STACK_DIRECTION 1) ## Stack grows direction
## If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts
## to issue such a statement receives the following error message:
## ERROR 1148: The used command is not allowed with this MySQL version
SET(ENABLED_LOCAL_INFILE 1)
#SET(WITH_EMBEDDED_SERVER TRUE)
SET(HAVE_LLVM_LIBCPP OFF)
SET(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE 1)
SET(HAVE_IB_GCC_SYNC_SYNCHRONISE 1)
SET(HAVE_IB_GCC_ATOMIC_THREAD_FENCE 1)
SET(HAVE_IB_GCC_ATOMIC_COMPARE_EXCHANGE 1)
SET(HAVE_IB_ATOMIC_PTHREAD_T_GCC 1)
SET(HAVE_IB_LINUX_FUTEX 1)
SET(HAVE_GCC_ATOMICS_WITH_ARCH_FLAG 1)
SET(HAVE_FUNC_IN_CXX 1)
SET(HAVE___BUILTIN_FFS 1)
IF(CMAKE_COMPILER_IS_GNUCC)
SET(HAVE_C_FLOATING_POINT_FUSED_MADD 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(HAVE_CXX_FLOATING_POINT_FUSED_MADD 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCC)
SET(HAVE_C_SHIFT_OR_OPTIMIZATION_BUG 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG 1)
ENDIF()
==========以上,根据自己环境路径修改===========
3. 接着执行以下Cmake:
cmake . -DWITH_BOOST=/usr/local/boost_1_59_0/ -DCMAKE_INSTALL_PREFIX=/home/arm/mysql -DCMAKE_TOOLCHAIN_FILE=./imx.cmake -DCURSES_LIBRARY=/home/arm/ncurses-6.1/lib -DCURSES_INCLUDE_PATH=/home/arm/ncurses-6.1/include -DHAVE_C_SHIFT_OR_OPTIMIZATION_BUG_EXITCODE=1 -DHAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG_EXITCODE=1 -DHAVE_C_FLOATING_POINT_FUSED_MADD_EXITCODE=1 -DHAVE_CXX_FLOATING_POINT_FUSED_MADD_EXITCODE=1
cmake 过程的错误:
1.如果出现以下找不到库的问题;建议重新安装交叉编译环境吧,
2.
-DHAVE_C_SHIFT_OR_OPTIMIZATION_BUG_EXITCODE=1 -DHAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG_EXITCODE=1 -DHAVE_C_FLOATING_POINT_FUSED_MADD_EXITCODE=1 -DHAVE_CXX_FLOATING_POINT_FUSED_MADD_EXITCODE=1
将以上配置加入cmake中,重新cmake
4. cmake成功后直接执行make
make过程的错误:
1.未将编译好pc版的extra/comp_err scripts/comp_sql sql/gen_lex_hash sql/gen_lex_token extra/protobuf/protoc libmysql/libmysql_api_test拷贝到/usr/bin/目录下
- $ cp extra/comp_err /usr/bin/
- $ cp scripts/comp_sql /usr/bin/
- $ cp sql/gen_lex_hash /usr/bin/
- $ cp sql/gen_lex_token /usr/bin/
- $ cp extra/protobuf/protoc /usr/bin/
- $ cp libmysql/libmysql_api_test /usr/bin/
2.xcom_transport.c未能找到rpc_inline_t类型
进入目录/opt/mysql/mysql-5.7.25-arm-bat/rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/
找到文件并打开, xcom_transport.c
转到443行代码或搜索rpc_inline_t,将其替换成long类型,在make
3. 未能找到comp_sql执行程序
将/opt/mysql/mysql-5.7.25-pc/scripts下编译好的comp_sql拷贝到/opt/mysql/mysql-5.7.25-arm/scripts
在make
5. 最后make install
6.移植ARM版到设备上
1. 将编译好的mysql打包并cp到设备的/usr/local/下
2. 新一个脚本sql.sh,将以下添加到脚本中:
#!/bin/bash MYSQL_BASE=/usr/local/mysql echo "Setup the mysql-5.7.23....." echo "Create the data path ${MYSQL_BASE}/data..." mkdir -p ${MYSQL_BASE}/data echo "Initailize the data directory and create the MySQL grant tables" ${MYSQL_BASE}/bin/mysqld --user=root --basedir=${MYSQL_BASE} --datadir=${MYSQL_BASE}/data --initialize-insecure ##--initialize echo "copy mysqld config file to /etc/ " cp my.cnf /etc/my.cnf echo "Create link to /usr/bin" ln -s ${MYSQL_BASE}/bin/mysqld /usr/bin/mysqld ln -s ${MYSQL_BASE}/bin/mysql /usr/bin/mysql ln -s ${MYSQL_BASE}/bin/my_print_defaults /usr/bin/my_print_defaults ln -s ${MYSQL_BASE}/bin/mysqladmin /usr/bin/mysqladmin ln -s ${MYSQL_BASE}/bin/mysqldump /usr/bin/mysqldump echo "Starting and Stopping MySQL Automatically.... " cp ${MYSQL_BASE}/support-files/mysql.server /etc/init.d/mysqld /usr/sbin/update-rc.d mysqld defaults 98 echo "No passwd for mysql, you can use the following command to login: " echo "mysql -u root --skip-password " echo "[Done]" exit 0;
3. 在新建一个配置文件my.conf,将以下配置添加进去,根据自己的需求修改
######################################################## ###### mysql configure file ######################################################## [mysqld]
- user=root
- port=3306
- datadir=/usr/local/mysql/data
- basedir=/usr/local/mysql
- socket=/tmp/mysql.sock
- pid-file=/var/run/mysqld.pid
- general-log-file=/var/log/mysqld.log
- slow-query-log-file=/var/log/mysqld.log
- log-error=/var/log/mysqld.log
- [client]
- port=3306
- socket=/tmp/mysql.sock
4. 最后执行以下sql.sh脚本、
大功告成