0

I am trying to install the RMariaDB package (on macOS), but install.packages("RMariaDB") fails with the following message:

-----------------------------[ ANTICONF ]-----------------------------
Configure could not find suitable mysql/mariadb client library. Try installing:
 * deb: libmariadb-dev (Debian, Ubuntu)
 * rpm: mariadb-connector-c-devel | mariadb-devel | mysql-devel (Fedora, CentOS, RHEL)
 * csw: mysql56_dev (Solaris)
 * brew: mariadb-connector-c (OSX)
If you already have a mysql client library installed, verify that either
mariadb_config or mysql_config is on your PATH. If these are unavailable
you can also set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------[ ERROR MESSAGE ]----------------------------
<stdin>:1:10: fatal error: 'mysql.h' file not found
#include <mysql.h>
         ^~~~~~~~~
1 error generated.
-----------------------------------------------------------------------

I'm confused because I've installed both mariadb-connector-c and mysql-connector-c++ using brew install, and added the directories containing each mariadb_config and mysql_config to my PATH:

~ % echo $PATH | tr ':' '\n'
/usr/local/mysql-9.1.0-macos14-x86_64/bin
/usr/local/Cellar/mariadb-connector-c/3.4.3/bin
/usr/local/opt/mariadb-connector-c/bin
[TRUNCATED...]

~ % mariadb_config
Copyright 2011-2020 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: mariadb_config [OPTIONS]
Compiler: Clang 16.0.0.16000026
[TRUNCATED...]

~ % mysql_config
Usage: /usr/local/mysql-9.1.0-macos14-x86_64/bin/mysql_config [OPTIONS]
Compiler: AppleClang 15.0.0.15000100
[TRUNCATED...]

Why can't mariadb_config or mysql_config be found despite being on my PATH?

I have noticed the hint you can also set INCLUDE_DIR and LIB_DIR manually via: R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...', but I don't know what to enter for ....

I am on R 4.4.2 and macOS 14.6.1:

R.Version()[c("platform", "version.string")]
#> $platform
#> [1] "x86_64-apple-darwin23.6.0"
#> 
#> $version.string
#> [1] "R version 4.4.2 (2024-10-31)"

And here is the full output from install.packages("RMariaDB"):

Installing package into ‘/usr/local/lib/R/4.4/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/RMariaDB_1.3.3.tar.gz'
Content type 'application/x-gzip' length 910240 bytes (888 KB)
==================================================
downloaded 888 KB

* installing *source* package ‘RMariaDB’ ...
** package ‘RMariaDB’ successfully unpacked and MD5 sums checked
** using staged installation
Homebrew 4.4.15
Using PKG_CFLAGS=
Using PKG_LIBS=-lmysqlclient
Using PKG_PLOGR=
-----------------------------[ ANTICONF ]-----------------------------
Configure could not find suitable mysql/mariadb client library. Try installing:
 * deb: libmariadb-dev (Debian, Ubuntu)
 * rpm: mariadb-connector-c-devel | mariadb-devel | mysql-devel (Fedora, CentOS, RHEL)
 * csw: mysql56_dev (Solaris)
 * brew: mariadb-connector-c (OSX)
If you already have a mysql client library installed, verify that either
mariadb_config or mysql_config is on your PATH. If these are unavailable
you can also set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------[ ERROR MESSAGE ]----------------------------
<stdin>:1:10: fatal error: 'mysql.h' file not found
#include <mysql.h>
         ^~~~~~~~~
1 error generated.
-----------------------------------------------------------------------
ERROR: configuration failed for package ‘RMariaDB’
* removing ‘/usr/local/lib/R/4.4/site-library/RMariaDB’
Warning in install.packages :
  installation of package ‘RMariaDB’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/r0/g_153g5n41n_rcdb3dkv72940000gq/T/RtmpfDfDGC/downloaded_packages’
1
  • Looks like headers for mySQL cannot be found at time of compilation. Sometimes brew installs end up in directories that the standard version of R cannot find. This may require configuration instructions during installation (as the error message states. ) Commented Jan 10 at 9:40

2 Answers 2

0

The path that the anticonf script uses to look for mariadb_config and mysql_config is (as far as I can tell) not affected by prepending $PATH using, e.g.,

# suggestion from homebrew for adding mariadb_config to the PATH
echo 'export PATH="/usr/local/opt/mariadb-connector-c/bin:$PATH"' >> ~/.zshrc
. ~/.zshrc

which is why it could not find them.

Instead, adding the path to /usr/paths and restarting the machine works.

The alternative of specifying LIB_DIR and IMPORT_DIR also works, but it wasn't obvious to me where to find the directories or how to format them - so here is a function that will handle those details given the path to mariadb_config or mysql_config:

install_rmariadb <- function(config_path) {
  install.packages("RMariaDB",
    type = "source",
    configure.vars = sprintf(
      "INCLUDE_DIR='%s' LIB_DIR='%s'",
      system(paste(config_path, "--variable=pkgincludedir"), intern = TRUE),
      system(paste(config_path, "--variable=pkglibdir"), intern = TRUE)
    )
  )
}

install_rmariadb("/usr/local/opt/mariadb-connector-c/bin/mariadb_config")
Sign up to request clarification or add additional context in comments.

Comments

0

The answer above didn't work for me. Unfortunately the process below uses terminal which many R users are unfamiliar with, but worked for me on an M2 mac running Sequoia.

On my ARM mac, homebrew is in /opt/homebrew, but on intel this is different, and can be changed. see https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location

The installer for RMariaDB did use the system path for me when looking for the binary mysql_config if I ran R in the same terminal. Note that I didn't have to put that path into my shell config (bashrc, zshrc etc) because I only needed it for the installer once.

I had to use find to see where brew actually installed mysql_config, but first had to find where homebrew was using which brew which gave me /opt/homebrew/bin/brew so see the find command below. I think $HOMEBREW_PREFIX may also provide a clude. Please change the path in find to match your system. Here are the steps I took in the Mac terminal with home brew installed.

  1. install libs using homebrew

brew install mysql-connector-c++ brew install mariadb-connector-c

  1. find out where mysql_config was installed

find /opt/homebrew -iname "mysql_config"

was /opt/homebrew/Cellar/mariadb-connector-c/3.4.4/bin for me

  1. set the path and start R from that terminal

This will not work in Rstudio, another terminal, or R GUI

export PATH=$PATH:/opt/homebrew/Cellar/mariadb-connector-c/3.4.4/bin`
R
  1. Now install the package
install.packages('RMariaDB')

And it worked from here out in all Rstudio sessions.

Here are all the shell commands in one go (tested in zsh on Arm MacOS 15 Sequoia only with homebrew installed)

# MacOS zsh
brew install mysql-connector-c++
brew install mariadb-connector-c
MYSQL_CONFIG_PATH=$(dirname `find /opt/homebrew -iname "mysql_config"`)
# should check that this was actually found else MYSQL_CONFIG_PATH will be blank
export PATH=$PATH:MYSQL_CONFIG_PATH
Rscript -e "install.packages('RMariaDB', repos='https://cran.rstudio.com')"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.