Using Native MariaDB Binaries in Linux

The latest release of MariaDB4j still uses MariaDB 10.2.11. We were running into an issue running this locally and needed a more recent version.

Install the MariaDB version you want:

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --os-type=rhel --os-version=7 --mariadb-server-version=10.6
sudo yum install mariadb-server
yum list installed | grep maria

You should see:

MariaDB-client.x86_64               10.6.12-1.el7.centos             @mariadb-main
MariaDB-common.x86_64               10.6.12-1.el7.centos             @mariadb-main
MariaDB-compat.x86_64               10.6.12-1.el7.centos             @mariadb-main
MariaDB-server.x86_64               10.6.12-1.el7.centos             @mariadb-main

Mnaually configure your MariaDb4jService in lieu of the Spring version:

  @Bean
  public MariaDB4jService mariaDB4jService(@Value("${mariaDB4j.port}") int port) {
    MariaDB4jService mariaDB4jService = new MariaDB4jService();
    DBConfigurationBuilder dbConfigurationBuilder = mariaDB4jService.getConfiguration();
    dbConfigurationBuilder.setPort(port);
    dbConfigurationBuilder.setUnpackingFromClasspath(false);
    dbConfigurationBuilder.setLibDir(SystemUtils.JAVA_IO_TMPDIR + "/MariaDB4j/no-libs");
    dbConfigurationBuilder.setBaseDir("/usr");
    dbConfigurationBuilder.setExecutable(Server, "/usr/sbin/mysqld");
    dbConfigurationBuilder.build();
    return mariaDB4jService;
  }

  @Bean
  public DataSource dataSource(
      MariaDB4jService mariaDB4jService,
      @Value("${mariaDB4j.databaseName}") String databaseName,
      @Value("${spring.datasource.username}") String datasourceUsername,
      @Value("${spring.datasource.password}") String datasourcePassword,
      @Value("${spring.datasource.driver-class-name}") String datasourceDriver)
      throws ManagedProcessException {

    mariaDB4jService.getDB().createDB(databaseName);
    DBConfigurationBuilder config = mariaDB4jService.getConfiguration();

    return DataSourceBuilder.create()
        .username(datasourceUsername)
        .password(datasourcePassword)
        .url(config.getURL(databaseName))
        .driverClassName(datasourceDriver)
        .build();
  }