First attempt to get Rust to communicate with a database. I believe Diesel is a widely used crate for connecting to databases. However, if there is a more MariaDB-friendly crate I'd gladly switch to that.
Rust: version 1.78
Mariadb: version "mariadb Ver 15.1 Distrib 10.7.3-MariaDB, for Win64 (AMD64)"
I've been following these Diesel "getting started" instructions. I got as far as making (and re-doing) the migrations. As explained there, this automatically creates a file "schema.rs", which in my case looks like this:
diesel::table! {
posts (id) {
id -> Unsigned<Integer>,
#[max_length = 50]
title -> Varchar,
body -> Text,
published -> Bit,
}
}
My up.sql
file, in order to be valid MariaDB SQL, is like this:
CREATE TABLE posts (
id int(11) UNSIGNED NOT NULL,
title VARCHAR(50) NOT NULL,
body TEXT NOT NULL,
published BIT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (id)
)
However, when I then try to run the first cargo run
command, namely cargo run --bin show_posts
, I get the following error:
error: failed to run custom build command for `mysqlclient-sys v0.3.1`
...
Caused by:
process didn't exit successfully: `D:/apps/rust/auto_generated/diesel_demo/target\debug\build\mysqlclient-sys-c22c8c5dcbc4ae83\build-script-build` (exit code: 101)
--- stdout
cargo::rerun-if-env-changed=MYSQLCLIENT_VERSION
cargo::rerun-if-env-changed=MYSQLCLIENT_LIB
... # about 50 more lines like this
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at D:\apps\rust\rust_1.70.0\.cargo\registry\src\index.crates.io-6f17d22bba15001f\mysqlclient-sys-0.3.1\build.rs:77:5:
Did not find a compatible version of libmysqlclient.
Ensure that you installed one and teached mysqlclient-sys how to find it
You have the following options for that:
...
NB "compatible version of libmysqlclient".
Can someone explain what I need to do at this point? I believe I'm getting this because I'm trying to use Rust designed for MySQL with MariaDB, but it could be another reason. My research seems to show that MariaDB instead has a "dbase connector" (which I have installed, and use with Python). It seems that this is its equivalent to libmysqlclient. But again I could be completely wrong.
But it appears that the Diesel crate, with the "mysql" feature, requires the presence of "libmysqlclient". Does anyone know whether using MariaDB is still possible? Or is this doomed to fail? Can any Rust database crate work with MariaDB?