3

So, I want to use Mariadb. There is this Connector-C for it. https://downloads.mariadb.org/connector-c/

How do I install it? Quiet frankly, the documentation for it is horrible. Even the src file for 3.0.5 is linked to 3.0.4 page.

I did not find a way to install the binary, and the documentation for building from src is quiet vague. I would prefer to know how to install both ways (binary and build from source)

I'm using CentOS7 64bit.

Ahmad Bilal
  • 380
  • 1
  • 2
  • 15

4 Answers4

9

The easiest way to install it would be to use the MariaDB package repository.

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum -y install MariaDB-devel

As for building from source, these steps should work on CentOS 7.

sudo yum -y install git gcc openssl-devel make cmake
git clone https://github.com/MariaDB/mariadb-connector-c.git
mkdir build && cd build
cmake ../mariadb-connector-c/ -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
markusjm
  • 2,358
  • 1
  • 11
  • 23
  • 1
    The documentation also suggests to make a dir named build (the code for which you have provided as well), but where is the ideal location to make this dir? – Ahmad Bilal Aug 01 '18 at 16:38
  • when we do cmake, what is the default path where mariadb-connector-c is cloned on our local system? – Ahmad Bilal Aug 01 '18 at 16:40
  • By default CMake installs all programs to `/usr/local`. Most of the time you want to install it into `/usr` instead. – markusjm Aug 02 '18 at 17:08
  • On the directory location, pretty much anywhere is fine. It won't be used after the installation is done so it can be removed. – markusjm Aug 02 '18 at 17:09
  • 1
    if you want to specify another location, just use -DCMAKE_INSTALL_PREFIX=your_location when running cmake. – Georg Richter Aug 04 '18 at 08:27
7

Raspberry Pi OS

cd to preferred build location. Then install (thanks to @markusjm!):

sudo apt install git gcc make cmake libssl-dev
git clone https://github.com/MariaDB/mariadb-connector-c.git
mkdir build && cd build
cmake ../mariadb-connector-c/ -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install

Then add installation directory to LD_LIBRARY_PATH. Note: my installation directory is /usr/lib/mariadb. If you cannot find this after your installation, search for e.g. libmariadb.so, a file that should reside in your installation folder.

export LD_LIBRARY_PATH=/usr/lib/mariadb:$LD_LIBRARY_PATH

Afterwards you can finally pip3 install mariadb, if, like me, you tried to do that in the first place.

smcs
  • 1,772
  • 3
  • 18
  • 48
6

And for Ubuntu 20.04...

sudo apt-get install libmariadb3 libmariadb-dev
Harley
  • 1,305
  • 1
  • 13
  • 28
5

After you download MariaDB Connector/C, untar and cd. Then mv the executable first.

sudo mv -f bin/mariadb_config /usr/bin/

Now you can execute mariadb_config and will know where to put header and library files to build wheel for mariadb.

For example,

Ubuntu 18.04

sudo mv -f include/mariadb /usr/local/include/
sudo mv -f lib/mariadb     /usr/local/lib/

CentOS 7 & Ubuntu 20.04

sudo mv -f include/mariadb /usr/include/
sudo mv -f lib/mariadb     /usr/lib/

Finally, you could pip install mariadb. (Or, export CFLAGS=-std=c99 may help.)

After, in the case you cannot import mariadb,

export LD_LIBRARY_PATH=/PATH/TO/where/you/mv/lib/mariadb
ghchoi
  • 4,812
  • 4
  • 30
  • 53