Any MySql Libraries That Actually Work?

I’m looking for a MySql library where I can connect to and query my database. It’s a db for work, so I have no control over the choice of MySql.

After reviewing https://ocamlverse.github.io/content/databases.html , I tried sequoia, which does not install due to my compiler being at 4.08. I’ve tried mysql, which does not even compile. opam says the stubs throw 3 warnings and 20 errors.

Both packages don’t seem active enough to give me any hope that these issues will be resolved. I don’t think the other mysql libraries listed on ocamlverse are what I am looking for either.

I’ve attempted to fork of ocaml-mysql and make it compile with mysql 8 connector: https://github.com/chrisnevers/mysql8 but I would ideally like the original to work.

Any help with either issue is greatly appreciated. :frowning: I’m on Mac if it’s of any concern

3 Likes

Have you seen ppx_mysql? https://engineering.issuu.com/2019/05/06/announcing-ppx-mysql

Yeah I reviewed the blog, it seems like a cool idea, but it doesn’t actually provide the mysql connection as its just a ppx rewriter

But is there anything wrong with the underlying library they use ? That is ocaml-mysql ? Never used it but seems to be the basic thing you are asking for (understood as “looking for a MySql library where I can connect to and query my database”).

My memory is that ocaml-mysql works. Um, @chrisnevers, it might be worth giving it a try? And if it doesn’t work, reporting back on what failed; maybe we can help debug?

I couldn’t get ocaml-mysql installing with opam. Here’s the log I receive:

The following actions will be performed:
  ∗ install mysql 1.2.4

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[mysql.1.2.4] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ERROR] The compilation of mysql failed at "/Users/cnevers/.opam/opam-init/hooks/sandbox.sh build 
make".

#=== ERROR while compiling mysql.1.2.4 ========================================#
# context     2.0.5 | macos/x86_64 | ocaml-base-compiler.4.08.0 | https://opam.ocaml.org#7acd4b61
# path        ~/.opam/4.08.0/.opam-switch/build/mysql.1.2.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build make
# exit-code   2
# env-file    ~/.opam/log/mysql-1000-d2d111.env
# output-file ~/.opam/log/mysql-1000-d2d111.out
### output ###
# mysql_stubs.c:376:7: error: use of undeclared identifier 'ret'
# [...]
#       ^
# mysql_stubs.c:440:1: warning: missing field 'fixed_length' initializer [-Wmissing-field-initializers]
# };
# ^
# mysql_stubs.c:903:1: warning: missing field 'fixed_length' initializer [-Wmissing-field-initializers]
# };
# ^
# fatal error: too many errors emitted, stopping now [-ferror-limit=]
# 3 warnings and 20 errors generated.
# make[1]: *** [mysql_stubs.o] Error 2
# make: *** [byte-code-library] Error 2


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build mysql 1.2.4
 └─
─ No changes have been performed

It seems the ocaml-mysql opam package requires conf-mariadb maybe something needs to be done for checking for mysql in that package at the opam repository level.

I’m not up-to-date with the maria/mysql fork information but in any case, I managed to install ocaml-mysql with:

# brew install mysql # opam's conf-mariadb wouldn't  find this
brew install mariadb 
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" # somehow my libssl was not found
opam install mysql

I’m running Ubuntu 18.04.4 LTS. I was able to install thus:

sudo apt-get install  libmariadbclient-dev
opam install mysql

I didn’t test it out (b/c don’t have any databases handy).
Just to see that it works, you might try firing up an Ubuntu VM and run inside there (connect to your DB); then you’ll know that it’s a local build problem, and not a problem with the driver/binding.

The mysql package only compiles with older MySQL, at work we use versions before 8 since that changed the API.

1 Like

Yeah that seems to be the issue. I have no say in reverting MySql versioning at work. So I guess I’ll use my fork thats compatible with MySql 8 for now. Thanks everyone for the help! :slightly_smiling_face:

3 Likes

The “good” thing is that the wire protocol is compatible I think so you can probably also use the “old” connector to compile the C bindings (on your machine or in Docker) and use that to talk to the “new” MySQL.

1 Like