How can I use MariaDB instead of MySQL in my Rails project?
When I try to install mysql2 gem it returns error,because mysqlclient was not found.
Here some soluti
For recent ubuntu 15.04 vivid and Debian 8.0 Jessie:
No need to install from a ppa (mariadb-server
is included), but you have to install libmariadb-client-lgpl-dev
and libmariadb-client-lgpl-dev-compat
and configure the gem to use mariadb_config
:
apt-get install mariadb-server libmariadb-client-lgpl-dev libmariadb-client-lgpl-dev-compat
gem install mysql2 -- --with-mysql-config=/usr/bin/mariadb_config
# or for bundler
bundle config build.mysql2 --with-mysql-config=/usr/bin/mariadb_config
bundle install
Probably you are getting error related with mariadb_config. Something like
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/dev/.rbenv/versions/2.1.5/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mariadb_config
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Cannot find mysql_config at /usr/bin/mariadb_config
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details.
You just need to go to /usr/bin directory and run this command
sudo ln -nfs mysql_config mariadb_config
This will solve your problem.
On linux mint, I was able to install:
sudo aptitude install libmariadbclient-dev:i386 libmariadbclient-dev
In Ubuntu 14.04.3 LTS
I am able to install with sudo apt-get install libmariadbd-dev
I followed https://mariadb.com/kb/en/mariadb/installing-mariadb-deb-files/ to install MariaDB which adds apt repository for maria db.
It doesn't look like openSUSE has a MariaDB client development package. You must install the libmysqlclient-devel package package. Since MariaDB is tagged as a drop in replacement for MySQL, it would have to support the MySQL clients, though you may lose tiny bits of MariaDB improvements.
It appears that the mysql2 gem should function with the MariaDB client libraries. Other options are hoping the mariadb-client package is enough, find a 3rd party package for the libraries or installing them yourself.
Update There is now an MariaDB repository for openSUSE. It includes a development package, and very good instructions. Place the following in a file under /etc/zypp/repos.d/
# MariaDB 10.1 openSUSE repository list - created 2015-10-20 16:37 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/opensuse13-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Now you can run zypper install MariaDB-client MariaDB-devel
Your question isn't about Ubuntu, but I'm sure a lot of people Googling Ubuntu (or its derivatives like Mint) will land on this page. In Ubuntu, you have to install all the packages using the MariaDB Foundation's ppa, but they include all the development libraries and support the 5.5, 10.0 and 10.1 releases. Then you can install packages such as mariadb-server
, mariadb-client
, libmariadbclient-dev
, and libmariadbclient-dev:i386
(32-bit client).
The instructions are simple and detailed on the site. For example, installing just the 10.1 dev libraries in Ubuntu 14.04
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirrors.syringanetworks.net/mariadb/repo/10.1/ubuntu trusty main'
sudo apt-get update
sudo apt-get install libmariadbclient-dev
As of Rails 5 (currently still in beta), MariaDB is officially supported, which I think should ease the implementation. Although I haven't tried it myself.
You can read about it in the blogpost on the Rails weblog:
http://weblog.rubyonrails.org/2016/4/16/this-week-in-rails-mariadb-action-cable-and-more/