Build Environment and Prerequisites
The host system is Ubuntu 20.04. The target device is an RV1126 ARM32 platform. The following directories define the workspace structure:
- Toolchain Path: /opt/toolchains/arm-linux-gnueabihf/bin
- Sysroot: /opt/rv1126-sdk/sysroot
- Workspace: /workspace/mysql-build
Dependency Preparation
Boost Library
Download and extract the Boost source code. MySQL requires specific headers from this library, so compilation is not necessary.
cd /workspace/mysql-build
tar -xjf boost_1_77_0.tar.bz2
OpenSSL
MySQL requires OpenSSL. A two-stage build process is recommended: first for the host (x86_64) to generate tools, and second for the target (ARM).
Stage 1: Host Build
tar -xzf openssl-1.1.1f.tar.gz
cd openssl-1.1.1f
./config no-asm shared --prefix=$PWD/__install
make -j$(nproc)
make install
Stage 2: Target Build
cd /workspace/mysql-build
tar -xzf openssl-1.1.1f.tar.gz
cd openssl-1.1.1f
./Configure linux-generic32 shared --prefix=$PWD/__install --cross-compile-prefix=/opt/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
Edit the generated Makefile to remove any instances of -m64, then compile:
make -j$(nproc)
make install
Ncurses
Similarly, build Ncurses for both architectures.
Stage 1: Host Build
tar -xzf ncurses-6.4.tar.gz
cd ncurses-6.4
./configure --prefix=$PWD/__install --with-yielding-select=no
make -j$(nproc)
make install
Stage 2: Target Build
cd /workspace/mysql-build
tar -xzf ncurses-6.4.tar.gz
cd ncurses-6.4
export PATH="/opt/toolchains/arm-linux-gnueabihf/bin:$PATH"
./configure --prefix=$PWD/__install --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc
make -j$(nproc)
make install
Native MySQL Build (x86_64)
Building the native version first is crucial because the cross-compilation process will attempt to use build tools generated during the build. If these tools are compiled for ARM, they cannot run on the host.
tar -xzf mysql-8.0.35.tar.gz
cd mysql-8.0.35
mkdir build-native && cd build-native
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/workspace/mysql-build/mysql-native \
-DMYSQL_DATADIR=/workspace/mysql-build/mysql-native/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/workspace/mysql-build/boost_1_77_0 \
-DWITH_SSL=system \
-DOPENSSL_ROOT_DIR=/workspace/mysql-build/openssl-1.1.1f/__install \
-DCURSES_INCLUDE_PATH=/workspace/mysql-build/ncurses-6.4/__install/include \
-DCURSES_LIBRARY=/workspace/mysql-build/ncurses-6.4/__install/lib/libncurses.a \
-DWITH_LIBEVENT=bundled \
-DWITH_UNIT_TESTS=0
make -j$(nproc)
make install
Cross-Compiling MySQL for ARM32
Configure the build using the ARM toolchain and dependencies.
cd /workspace/mysql-build/mysql-8.0.35
mkdir build-arm && cd build-arm
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/workspace/mysql-build/mysql-arm \
-DMYSQL_DATADIR=/workspace/mysql-build/mysql-arm/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/workspace/mysql-build/boost_1_77_0 \
-DWITH_SSL=system \
-DOPENSSL_ROOT_DIR=/workspace/mysql-build/openssl-1.1.1f/__install \
-DCURSES_INCLUDE_PATH=/workspace/mysql-build/ncurses-6.4/__install/include \
-DCURSES_LIBRARY=/workspace/mysql-build/ncurses-6.4/__install/lib/libncurses.a \
-DWITH_LIBEVENT=bundled \
-DWITH_UNIT_TESTS=0 \
-DCMAKE_C_COMPILER=/opt/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \
-DCMAKE_CXX_COMPILER=/opt/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \
-DCMAKE_SYSTEM_PROCESSOR=arm \
-DCMAKE_FIND_ROOT_PATH=/opt/rv1126-sdk/sysroot \
-DRESOLV_LIBRARY=/opt/rv1126-sdk/sysroot/usr/lib/libresolv.so
Resolving Libevent Version Check
Modify cmake/libevent.cmake in the source directory to bypass version detection failures. Hardcode the version in the function FIND_LIBEVENT_VERSION to ensure the build passes.
Handling Exec Format Errors
During the cross-compilation, the build system will create ARM binaries for various utilities (e.g., protoc, comp_err). When make invokes these, they will fail with "Exec format error" because the host cannot execute ARM binaries.
Solution: Create a backup directory for ARM-specific binaries, and immediately replace them with the x86_64 versions generated in the build-native step.
Example Script for Replacement:
# Create a stash for ARM binaries
mkdir -p ../arm-stash/bin
mkdir -p ../arm-stash/lib
# Function to swap binary
swap_binary() {
local bin_name=$1
# Backup the ARM version if it exists
if [ -f "runtime_output_directory/$bin_name" ]; then
cp "runtime_output_directory/$bin_name" "../arm-stash/bin/$bin_name"
fi
# Replace with x86 version
cp ../build-native/runtime_output_directory/$bin_name runtime_output_directory/
}
# Execute swaps for failing tools
swap_binary "protoc"
swap_binary "comp_err"
swap_binary "comp_sql"
swap_binary "gen_lex_hash"
swap_binary "uca9dump"
swap_binary "xprotocol_plugin"
swap_binary "gen_keyword_list"
swap_binary "gen_lex_token"
swap_binary "comp_client_err"
# Handle library specific issues
cp library_output_directory/libmysqlclient.so.21.2.35 ../arm-stash/lib/
cp ../build-native/library_output_directory/libmysqlclient.so.21.2.35 library_output_directory/
After each replacement, run make -j1 again. Repeat this process whenever an "Exec format error" occurs for a utility.
Manual Assembly
The make install step may fail due to RPATH issues. Manually assemble the distribution:
cd /workspace/mysql-build
mkdir -p mysql-final/{bin,lib,include,etc}
# Copy generated content
cp -r mysql-8.0.35/build-arm/runtime_output_directory/* mysql-final/bin/
cp -r mysql-8.0.35/build-arm/library_output_directory/* mysql-final/lib/
cp -r mysql-8.0.35/include mysql-final/
# Restore ARM binaries that were replaced during build
cp arm-stash/bin/* mysql-final/bin/
cp arm-stash/lib/* mysql-final/lib/
# Verify architecture
file mysql-final/bin/mysqld
file mysql-final/lib/libmysqlclient.so
Deployment and Testing on RV1126
Transfer the mysql-final directory to the target device (e.g., /usr/local/mysql).
cd /usr/local/mysql
mkdir data
export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
# Initialize the database
./bin/mysqld --initialize --user=root --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# Start the daemon
./bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid --user=root
# Client connection
./bin/mysql -uroot -p -S /tmp/mysql.sock
Once logged in, update root permissions for remote access:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123';
FLUSH PRIVILEGES;
USE mysql;
UPDATE user SET host='%' WHERE user='root';
FLUSH PRIVILEGES;