MySql connector for OpenWrt (MIPS)

If you are interested in developing applications in C using MySQL on OpenWrt under MIPS, you will need the  connector to communicate to the data base. At MySQL web page you will find all connectors compiled for x86 and sources files for compiling to other architectures. Let’s see how to compile the connector for MIPS using those sources files:

  1. Download the  MySql connector for C (version 6.0.2 was used in this example).
  2. Extract the downloaded file enter into folder mysql-connector-c-6.0.2:
    tar xvzf mysql-connector-c-6.0.2.tar.gz
    cd mysql-connector-c-6.0.2
  3. Install cmake. In Debian (and spin-offs) just type:
     aptitude install cmake
  4. Set the cross-compiling environment for MIPS, by exporting the following variables:
    export CHROOT=/home/lgallard/backfire
    export TOOLCHAIN_PATH=$CHROOT/staging_dir/toolchain-mips_r2_gcc-4.3.3+cs_uClibc-
    export PATH=$PATH:$TOOLCHAIN_PATH/usr/bin/
    export AR=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-ar
    export AS=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-as
    export LD=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-ld
    export NM=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-nm
    export CC=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-gcc
    export CPP=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-cpp
    export GCC=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-gcc
    export CXX=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-g++
    export RANLIB=$TOOLCHAIN_PATH/usr/bin/mips-openwrt-linux-uclibc-ranlib
  5. Generate the Makefile:
    cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/install_path
  6. Compile the connector:
  7. Install the binaries:
    make install
  8. Verify if it was compiled for MIPS correctly:
    file /install_path/lib/
    /install_path/lib/ ELF 32-bit MSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped

Using the connector

Now you can use the connector in your C and MSQL projects on OpenWrt for MIPS, just add the paths for includes and libraries as follow:

gcc client.c -o client  -I/install_path/include -L/install_path/lib -lmysqlclient -lz -ldl

Learning the API

If you are interested in learning the API, I recommend you MySQL Developer’s Library de Paul DuBois book which has really good example in chapter 7 on how to do SQL prepared statements using the C connector for MySQL.



  1. #1 by Luis Gallardo on 16/09/2011 - 3:03 pm

    @Helio as far you get the sources you can compile any connector to other platform following these steps. Cheers!

  2. #2 by Helio Capella on 16/09/2011 - 2:54 pm

    Thanks a lot for this helpful guide, Is it possible to do the same with mysql c++ connector?

(will not be published)