This topic explains how to configure LabKey Server to retrieve and display data from a MySQL or MariaDB database as an
external data source. This topic assumes you have
reviewed the general guidance here and provides specific parameters and details for these database types.
MySQL and MariaDB Version Support
LabKey supports MySQL 5.5 and higher, and any currently supported version of MariaDB. LabKey connects to both databases using the MariaDB JDBC driver.
Configure the MySQL or MariaDB Data Source
The new external data source must have a
unique JNDI name that you will use in naming the properties you will define. In the example on this page, we use "externalMySqlDataSource", which will appear to users defining external schemas as "externalMySql". If you have more than one external data source, give each a unique name with the DataSource suffix ("firstExternalMySqlDataSource", "secondExternalMySqlDataSource", etc.). Learn more
here.
In the <LABKEY_HOME>/config/application.properties file, add a new section with the name of the datasource and the parameters you want to define. Provide your own server/port, <DB_NAME>, <DB_USERNAME>, and <DB_PASSWORD> where indicated:
context.resources.jdbc.externalMySqlDataSource.driverClassName=org.mariadb.jdbc.Driver
context.resources.jdbc.externalMySqlDataSource.url=jdbc:mariadb://localhost:3306/<DB_NAME>
context.resources.jdbc.externalMySqlDataSource.username=<DB_USERNAME>
context.resources.jdbc.externalMySqlDataSource.password=<DB_PASSWORD>
context.resources.jdbc.externalMySqlDataSource.validationQuery=SELECT 1
If an existing external data source in application.properties is still configured with the old MySQL driver, LabKey Server will fail to start with an error like:
The database driver "com.mysql.cj.jdbc.Driver" specified in data source "mySqlDataSource" is not supported in your installation.
Update the driverClassName, url, and validationQuery as shown above to resolve this.
There are additional properties you can set, as shown in the
template for the main "labkeyDataSource" in the application.properties file.
driverClassName
Use this as the
driverClassName for both MySQL and MariaDB:
url
The
url property takes this form. Substitute the correct server/port and database name:
jdbc:mariadb://localhost:3306/databaseName
validationQuery
Use "SELECT 1" as the trivial validation query:
context.resources.jdbc.@@extraJdbcDataSource@@.validationQuery=SELECT 1
Define a New External Schema
To define a new schema from this data source see
Set Up an External Schema.
Related Topics