Hi Stevie,
Good news: the MariaDB driver can already do this. It just takes a couple of extra steps, because the admin form and the extension don’t cover it yet. I tested it on Lucee 7.1.0.204 / Java 25 / Tomcat 11 with the MariaDB extension 3.5.3 (Connector/J 3.5.3), with skip-networking on in MariaDB, so the socket was the only way in.
Why the Host field doesn’t work
The MariaDB form builds jdbc:mariadb://{host}:{port}/{database}, so a socket path in Host leaves the driver without a valid host, and you get that error. The driver wants the socket as the localSocket URL option instead.
Step 1: make JNA available to the driver
Connector/J uses JNA for Unix sockets, and neither Lucee nor the extension ships it. Without JNA, the driver quietly falls back to TCP and fails with connect: The address can't be null. To fix that:
- Put the JNA jar (net.java.dev.jna:jna, any 5.x from 5.15 up; I used 5.17.0) into Tomcat’s
lib/ folder.
- Let the driver bundle see it through OSGi boot delegation with this JVM argument, e.g. in
bin/setenv.sh:
CATALINA_OPTS="$CATALINA_OPTS -Dorg.osgi.framework.bootdelegation=com.sun.jna,com.sun.jna.*"
This adds to Lucee’s default list, it doesn’t replace it. Restart Tomcat afterwards.
Step 2: a datasource with your own connection string
In Application.cfc:
this.datasources["mydsn"] = {
class: "org.mariadb.jdbc.Driver",
bundleName: "mariadb-java-client",
bundleVersion: "3.5.3", // match the version of your installed MariaDB extension
connectionString: "jdbc:mariadb://localhost/mydb?localSocket=/tmp/mariadb/mysqld.sock",
username: "myuser",
password: "mypassword"
};
To set it up in the admin instead, choose the “Other - JDBC Driver” type and enter the same class, connection string, bundle name and bundle version. That worked the same way in my test.
The localhost in the URL is just a placeholder, and no port is needed. select @@socket should return your socket path once connected.
Things to check
- The path must be the server’s socket (
SELECT @@socket), and the user Lucee/Tomcat runs as needs read/write access to the socket file and access to its directory. If MariaDB runs in a container, mount the socket directory into the Lucee container (e.g. -v /tmp/mariadb:/tmp/mariadb).
- Over the socket, MariaDB authenticates the user as
'myuser'@'localhost', not 'myuser'@'127.0.0.1' or a container IP, so the grants need to match.
- JNA unpacks a small native library on first use (into
~/.cache/JNA, or -Djna.tmpdir=...), so that location needs to be writable.
MySQL driver
You’re right about MySQL Connector/J: it has no Unix socket support of its own and needs a socket factory like junixsocket’s. Since the MariaDB driver talks to MySQL servers too, the route above is simpler.
Feature request
The MariaDB extension is a community extension by Julian Halliwell (cfsimplicity/lucee-mariadb), so a socket field in the form, and shipping JNA so Step 1 isn’t needed, would be a request on its GitHub issues. I checked that bundling JNA in the extension makes sockets work without the JVM argument, so it’s a small change.
Cheers,
Gian