MariaDB4j icon indicating copy to clipboard operation
MariaDB4j copied to clipboard

Reusing data dir

Open xtianus opened this issue 1 year ago • 3 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

@xtianus Thank You for your interest in this library, and providing this feedback. Would you be interested to contribute a PR which does the needful for you?

vorburger avatar Apr 05 '25 15:04 vorburger

#1042 sounds related BTW. Contributions to address this are welcome.

vorburger avatar Apr 05 '25 15:04 vorburger

@xtianus @Muta-Jonathan I'm assuming that [your!] the (just) merged #1166 addressed this; please comment to re-open if you disagree.

vorburger avatar Aug 03 '25 22:08 vorburger