MariaDB4j icon indicating copy to clipboard operation
MariaDB4j copied to clipboard

Reusing data dir

Open xtianus opened this issue 5 months ago • 0 comments

I'd like to reuse the data dir on multiple runs in order to keep my data.

Currently this can't be done because the DB.newEmbeddedDB() method always tries to initialize a new db in the data folder, which must be empty or I get the error

ch.vorburger.exec.ManagedProcess - : mariadb-install-db.exe: ERROR : Data directory C:\somefolder\mydata is not empty. 
Only new or empty existing directories are accepted for --datadir

So I forked the repo and implemented a openEmbeddedDB() method

public static DB openEmbeddedDB(DBConfiguration config) throws ManagedProcessException {
    DB db = new DB(config);
    db.prepareDirectories();
    return db;
}

but I still can't run the database on the same folder twice if I stop my java process with CTRL-C (on windows) because the mariadb.exe process is not stopped by the shutdown hooks and keeps running, preventing a restart of my application with the error

InnoDB: The data file './ibdata1' must be writable

as the mariadb.exe process locks ibdata1.

So I'm wondering if there's a way to reattach to an existing mariadb process that has been previously started. This may be a feature request I guess.

xtianus avatar Oct 01 '24 16:10 xtianus