Cross-compiling MySQL

MySQL is not very cross-compile friendly, but hey, let’s give it a try.

First steps

Download the source code of the Community Edition of the MySQL server. Extract it to two different folders:

1
2
3
4
tar xvf mysql-5.6.16.tar.gz
mv mysql-5.6.16 mysql-src-x86
tar xvf mysql-5.6.16.tar.gz
mv mysql-5.6.16 mysql-src-arm

Compile the x86 version (no, this is not a mistake, you have to compile it for your computer, because some necessary tools will only be available this way):

1
2
cd mysql-src-x86/BUILD
./compile-pentium

Cross-compiling libncurses

Download the latest source code of libncurses from here, extract and compile it:

1
2
3
4
5
6
cd /home/nonoo/mysql
tar xvf ncurses-5.9.tar.gz
cd ncurses-5.9
CC=arm-linux-gcc CXX=arm-linux-g++ ./configure --host=arm-linux-gnu --prefix=/usr
make
make install DESTDIR=/home/nonoo/mysql/libncurses-compiled

Configuring CMake

Create the CMake toolchain file mysql-src-arm/BUILD/toolchain-arm-linux.cmake:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_CROSSCOMPILING 1)

SET(CMAKE_C_COMPILER /home/storage1/work/olimex-imx-buildroot/output/host/usr/bin/arm-linux-gcc)
SET(CMAKE_CXX_COMPILER /home/storage1/work/olimex-imx-buildroot/output/host/usr/bin/arm-linux-g++)

SET(CMAKE_FIND_ROOT_PATH /home/storage1/work/olimex-imx-buildroot/output/host/usr/)
# These are set to never because we will add library dependency paths
# using CMAKE_LIBRARY_PATH below.
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)

SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /home/nonoo/mysql/libncurses-compiled/usr/lib)

SET(CMAKE_INSTALL_PREFIX /usr)

# MySQL specific settings
SET(STACK_DIRECTION 1)
SET(WITH_UNIT_TESTS OFF)
SET(WITH_EMBEDDED_SERVER TRUE)
SET(DEFAULT_CHARSET utf8)
SET(DEFAULT_COLLATION utf8_general_ci)

Create and run the script mysql-src-arm/BUILD/doconfig:

1
2
3
4
#!/bin/bash
rm CMakeCache.txt
path=`dirname $0`
cmake $path/.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain-arm-linux.cmake -DENABLE_DOWNLOADS=1

Preparing building

Create the script mysql-src-arm/BUILD/domake:

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
export PATH=$PATH:`pwd`/extra
export PATH=$PATH:`pwd`/../scripts

# These scripts are needed to be copied from the x86 dir every time before make
# runs because they will be overwritten with ARM versions after a while.
cp ../../mysql-src-x86/BUILD/sql/gen_lex_hash sql/gen_lex_hash
export PATH=$PATH:`pwd`/sql
cp ../../mysql-src-x86/BUILD/storage/perfschema/gen_pfs_lex_token storage/perfschema/gen_pfs_lex_token
export PATH=$PATH:`pwd`/storage/perfschema/

make

We copy two files in the script before executing make. As you can see in the comment, the two scripts will be overwritten during building with the ARM versions so they can’t be run on the host system, and produce these errors:

1
2
[ 55%] Generating pfs_lex_token.h
/bin/sh: 1: gen_pfs_lex_token: not found
1
2
3
[ 62%] Building CXX object client/CMakeFiles/mysqladmin.dir/mysqladmin.cc.o
/home/nonoo/mysql/mysql-src-arm/sql/sql_lex.cc: In function 'void lex_init()':
/home/nonoo/mysql/mysql-src-arm/sql/sql_lex.cc:153:18: error: 'symbols' was not declared in this scope

Building

Run domake, it will abort with an error. As CMake uses multi-threading and runs several make instances in parallel, errors can be hard to find in the log. You should run domake several times, until each thread finishes early, so you can read the errors.

If you get this error:

1
2
[  4%] Generating ../include/mysqld_error.h, ../sql/share/english/errmsg.sys
/bin/sh: 1: comp_err: not found

Then copy all executables from mysql-src-x86/BUILD/extra to mysql-src-arm/BUILD/extra and mysql-src-arm/extra. Run domake again. If you get this error:

1
make[2]: *** No rule to make target `../scripts/comp_sql', needed by `scripts/mysql_fix_privilege_tables_sql.c'.  Stop.

Copy mysql-src-x86/BUILD/scripts/comp_sql to mysql-src-arm/scripts/comp_sql and try running domake again.

Installing

CMake supports the DESTDIR variable, so simply run:

1
make install DESTDIR=/home/nonoo/mysql/mysql-arm-compiled

You will find the cross-compiled MySQL in the $DESTDIR.

Kishore 2015-10-27 09:51:23

— Looking for strvis
— Looking for strvis – not found
— Looking for strunvis
— Looking for strunvis – not found
— Looking for include file libaio.h
— Looking for include file libaio.h – not found
— Looking for io_queue_init in aio
— Looking for io_queue_init in aio – not found
— Looking for sched_getcpu
— Looking for sched_getcpu – found
— Looking for asprintf
— Looking for asprintf – found
— Check size of pthread_t
— Check size of pthread_t – done
— Using cmake version 2.8.11.2
— Not building NDB
— Performing Test HAVE_PEERCRED
— Performing Test HAVE_PEERCRED – Success
— Library mysqlclient depends on OSLIBS -lpthread;m;dl
— GMOCK_SOURCE_DIR:/home/kishore/IEVCS_SoftwareBuild/mysql-5.6.20-srcarm/source_downloads/gmock-1.6.0
— Performing Test HAVE_NO_NULL
— Performing Test HAVE_NO_NULL – Success
— Performing Test HAVE_NO_UNUSED_TYPEDEFS
— Performing Test HAVE_NO_UNUSED_TYPEDEFS – Success
— GTEST_LIBRARIES:gmock;gtest
— Library mysqlserver depends on OSLIBS -lpthread;m;crypt;dl
— Configuring incomplete, errors occurred!

Can you please help me in resolving this issue

Nonoo 2015-10-27 11:40:37

Do you have the mentioned libs’ (libpthread, libcrypt libdl etc.) development packages installed?

 
 
Supriya 2015-10-29 13:27:38

Hello Nonoo,

I followed your procedure to compile mysql for arm and got the below error. Am clueless, where am I going wrong?
I got this error when I ran domake (./domake)

[ 22%] Built target perfschema_embedded
[ 22%] Building C object strings/CMakeFiles/strings.dir/dtoa.c.o
/mysql-src-arm/strings/dtoa.c: In function ‘my_strtod’:
/mysql-src-arm/strings/dtoa.c:471:1: error: insn does not satisfy its constraints:
(insn 3801 2064 2067 301 /mysql-src-arm/strings/dtoa.c:1978 (set (reg:DF 71 s8)
(mem/c:DF (plus:SI (reg/f:SI 11 fp)
(const_int -2084 [0xfffffffffffff7dc])) [0 %sfp+-2024 S8 A64])) 642 {*movdf_vfp} (nil))
/mysql-src-arm/strings/dtoa.c:471:1: internal compiler error: in reload_cse_simplify_operands, at postreload.c:402
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
make[2]: *** [strings/CMakeFiles/strings.dir/dtoa.c.o] Error 1
make[1]: *** [strings/CMakeFiles/strings.dir/all] Error 2
make: *** [all] Error 2

Nonoo 2015-10-29 13:40:54

You should try another version of the cross compiler toolchain.

 
 
Supriya 2015-10-29 13:44:13

Am using arm-arago-linux-gnueabi- toolchain
Which toolchain is recommended ?

 
Rexaline 2015-12-04 06:56:15

Which arm-linux toolchain version you are using in this cross compilation

Nonoo 2015-12-04 08:27:58

I can’t remember, it was nearly 2 years ago…

 
 
ramya 2020-06-17 12:09:05

hi,

i’m currently working on MySQL5.7.24-27. I want to integrate this one with yocto. i’m facing issue when building.

| /bin/sh: comp_err: command not found
| make[2]: *** [include/mysqld_error.h] Error 127
| make[1]: *** [extra/CMakeFiles/GenError.dir/all] Error 2
| make[1]: *** Waiting for unfinished jobs….

I have built in x86 and copied comp_err then also same error.

please provide any recipe available or inputs.

Regards,
Ramya

 
garrick 2020-09-07 12:39:03

export CXXFLAGS=-std=gnu++98
export CPPFLAGS=”-P”

you’d better add those two sentances

 
Name (required)
E-mail (required - never shown publicly)
Webpage URL
Comment:
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

Trackback responses to this post

About me

Nonoo
I'm Nonoo. This is my blog about music, sounds, filmmaking, amateur radio, computers, programming, electronics and other things I'm obsessed with. ... »

Twitter

Listening now

My favorite artists