[ACCEPTED]-Java, MySQL: Is there a way to embed a MySQL server with a Java program?-embedded-database
If you don't mind using MariaDB (the open 22 source variant of MySQL, basically works 21 the same) MariaDB4j can be the perfect option for 20 production enviroments.
MariaDB4j is a Java 19 (!) "launcher" for MariaDB (the 18 "backward compatible, drop-in replacement 17 of the MySQL(R) Database Server", see FAQ 16 and Wikipedia), allowing you to use MariaDB 15 (MySQL(R)) from Java without ANY installation 14 / external dependencies. Read again: You 13 do NOT have to have MariaDB binaries installed 12 on your system to use MariaDB4j!
As it works 11 completely without any requirements that 10 have to be on the users' pc it is probably 9 the best option to get MySQL embedded. Converting 8 a project that doesn't use an Embedded database 7 into MariaDB4j is as easy as calling:
DB db = DB.newEmbeddedDB(3306);
Read the github page for more information. Maven 6 central dependency is:
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>2.2.3</version>
</dependency>
You can combine this 5 with the newest driver to get access to 4 all functionality of MySQL 8.0 (win64
/win32
=windows, mac64
=macos, linux64
=linux):
<dependency>
<groupId>org.craftercms.mariaDB4j</groupId>
<artifactId>mariaDB4j-db-win64</artifactId>
<version>10.4.6.2</version>
</dependency>
If 3 you do mind using MariaDB, another option 2 is Wix Embedded MySQL.
Wix Embedded MySQL is a library that provides a way to 1 run real MySql within integration tests.
Why?
- Your tests can run on production-like environments: match version, encoding, timezone, database/schema/user settings;
- Its easy, much easier than installing right version by hand;
- You can use different versions/configuration per project without any local set-up;
- Supports multiple platforms: Windows, Linux, and OSX;
- Provides constantly updated multiple versions of MySql - 5.5, 5.6, 5.7, 8.0;
- Testing matrix for all supported OSes (x86/x64) and versions (5.5, 5.6, 5.7, 8.0).
A quick search shows this: MySQL Connector/MXJ 2 — for embedding MySQL server in Java applications 1 on the MySQL Downloads page at:
For future reference to anyone looking to 2 embed mysql, there is a utility from the 1 mysql guys that does this http://downloads.mysql.com/archives/c-mxj/
It sounds like you want an embedded database. While 6 MySQL Connector seems nice, it will launch 5 a separate server process. If you want 4 the database server to run in the Java virtual 3 machine, there are several embedded databases 2 for Java.
The two that I've seen used the 1 most are:
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.