MySQL Connector/MXJ is a solution for deploying the MySQL database
engine (mysqld
) intelligently from within a Java
package.
MySQL Connector/MXJ is a Java Utility package for deploying and managing a MySQL database. Deploying and using MySQL can be as easy as adding an additional parameter to the JDBC connection url, which will result in the database being started when the first connection is made. This makes it easy for Java developers to deploy applications which require a database by reducing installation barriers for their end-users.
MySQL Connector/MXJ makes the MySQL database appear to be a java-based component. It does this by determining what platform the system is running on, selecting the appropriate binary, and launching the executable. It will also optionally deploy an initial database, with any specified parameters.
Included are instructions for use with a JDBC driver and deploying as a JMX MBean to JBoss.
You can download sources and binaries from: http://dev.mysql.com/downloads/connector/mxj/
This a beta release and feedback is welcome and encouraged.
Please send questions or comments to the MySQL and Java mailing list.
Connector/MX
-
Connector/MXJ 5.x, currently in beta status, includes
mysqld
version 5.0.22 and includes binaries for Linux x86, Mac OS X PPC, Windows XP/NT/2000 x86 and Solaris SPARC. Connector/MXJ 5.x requires the Connector/J 5.x package. -
Connector/MXJ 1.x includes
mysqld
version 4.1.13 and includes binaries for Linux x86, Windows XP/NT/2000 x86 and Solaris SPARC. Connector/MXJ 1.x requires the Connector/J 3.x package.
This guide provides information on the Connector/MXJ 5.x release. For information on using the older releases, please see the documentation included with the appropriate distribution.
Connector/MXJ consists of a Java class, a copy of the
mysqld
binary for a specific list of
platforms, and associated files and support utilities. The Java
class controls the initialization of an instance of the embedded
mysqld
binary, and the ongoing management of
the mysqld
process. The entire sequence and
management can be controlled entirely from within Java using the
Connector/MXJ Java classes. You can see an overview of the
contents of the Connector/MXJ package in the figure below.
It is important to note that Connector/MXJ is not an embedded
version of MySQL, or a version of MySQL written as part of a
Java class. Connector/MXJ works through the use of an embedded,
compiled binary of mysqld
as would normally
be used when deploying a standard MySQL installation.
It is the Connector/MXJ wrapper, support classes and tools, that enable Connector/MXJ to appear as a MySQL instance.
When Connector/MXJ is initialized, the corresponding
mysqld
binary for the current platform is
extracted, along with a pre-configured data directed. Both are
contained within the Connector/MXJ JAR file. The
mysqld
instance is then started, with any
additional options as specified during the initialization, and
the MySQL database becomes accessible.
Because Connector/MXJ works in combination with Connector/J, you can access and integrate with the MySQL instance through a JDBC connection. When you have finished with the server, the instance is terminated, and, by default, any data created during the session is retained within the temporary directory created when the instance was started.
Connector/MXJ and the embedded mysqld
instance can be deployed in a number of environments where
relying on an existing database, or installing a MySQL instance
would be impossible, including CD-ROM embedded database
applications and temporary database requirements within a
Java-based application environment.
Connector/MXJ does not have a installation application or process, but there are some steps you can follow to make the installation and deployment of Connector/MXJ easier.
Before you start, there are some baseline requirements for
-
Java Runtime Environment (v1.4.0 or newer) if you are only going to deploy the package.
-
Java Development Kit (v1.4.0 or newer) if you want to build Connector/MXJ from source.
-
Connector/J 5.0 or newer.
Depending on your target installation/deployment environment you may also require:
-
JBoss - 4.0rc1 or newer
-
Apache Tomcat - 5.0 or newer
-
Sun's JMX reference implementation version 1.2.1 (from http://java.sun.com/products/JavaManagement/)
Connector/MXJ is compatible with any platform supporting Java
and MySQL. By default, Connector/MXJ incorporates the
mysqld
binary for a select number of
platforms, as outlined below.
-
Linux, i386
-
Windows NT, Windows 2000, Windows XP, x86
-
Solaris 8, SPARC 32 (compatible with Solaris 8, Solaris 9 and Solaris 10 on SPARC 32-bit and 64-bit platforms)
-
Mac OS X, PowerPC
For more information on packaging your own Connector/MXJ with the platforms you require, see Section 23.4.5.1, “Creating your own Connector/MXJ Package”
Because there is no formal installation process, the method, installation directory, and access methods you use for Connector/MXJ are entirely up to your individual requirements.
To perform a basic installation, choose a target directory for
the files included in the Connector/MXJ package. On Unix/Linux
systems you may opt to use a directory such as
/usr/local/connector-mxj
; On Windows, you
may want to install the files in the base directory,
C:\Connector-MXJ
, or within the
Program Files
directory.
To install the files:
-
Download the Connector/MXJ package, either in Tar/Gzip format (ideal for Unix/Linux systems) or Zip format (Windows).
-
Extract the files from the package. This will create a directory
connector-mxj
. Copy and optionally rename this directory to your desired location. -
For best results, you should update your global
CLASSPATH
variable with the location of the Connector/MXJ JAR (connextor-mxj.jar
). You will also need to add the AspectJ Runtime, located inlib/aspectjrt.jar
.Within Unix/Linux you can do this globally by editing the global shell profile, or on a user by user basis by editing their individual shell profile.
On Windows 2000, Windows NT and Windows XP, you can edit the global
CLASSPATH
by editing theEnvironment Variables
configured through theSystem
control panel.
Once you have extracted the Connector/MXJ and Connector/J
components you can run one of the sample applications that
initiates a MySQL instance. You can test the installation by
running the ConnectorMXJUrlTestExample
:
java ConnectorMXJUrlTestExample jdbc:mysql:mxj://localhost:3336/test?server.basedir=/var/tmp/test-mxj [MysqldResource] launching mysqld (getOptions) [/var/tmp/test-mxj/bin/mysqld][--no-defaults][--pid-file=/var/tmp/test-mxj/data/MysqldResource.pid][--socket=mysql.sock][--datadir=/var/tmp/test-mxj/data][--port=3336][--basedir=/var/tmp/test-mxj] [MysqldResource] launching mysqld (driver_launched_mysqld_1) InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created! 060726 15:40:42 InnoDB: Setting file ./ibdata1 size to 10 MB InnoDB: Database physically writes the file full: wait... 060726 15:40:43 InnoDB: Log file ./ib_logfile0 did not exist: new to be created InnoDB: Setting log file ./ib_logfile0 size to 5 MB InnoDB: Database physically writes the file full: wait... 060726 15:40:43 InnoDB: Log file ./ib_logfile1 did not exist: new to be created InnoDB: Setting log file ./ib_logfile1 size to 5 MB InnoDB: Database physically writes the file full: wait... InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 060726 15:40:44 InnoDB: Started; log sequence number 0 0 060726 15:40:44 [Note] /var/tmp/test-mxj/bin/mysqld: ready for connections. Version: '5.0.22-max' socket: 'mysql.sock' port: 3336 MySQL Community Edition - Experimental (GPL) [MysqldResource] mysqld running as process: 1210 ------------------------ 5.0.22-max ------------------------ [MysqldResource] stopping mysqld (process: 1210) 060726 15:40:44 [Note] /var/tmp/test-mxj/bin/mysqld: Normal shutdown 060726 15:40:45 InnoDB: Starting shutdown... 060726 15:40:48 InnoDB: Shutdown completed; log sequence number 0 43655 060726 15:40:48 [Note] /var/tmp/test-mxj/bin/mysqld: Shutdown complete [MysqldResource] clearing options [MysqldResource] shutdown complete
The above output shows an instance of MySQL starting, the necessary files being created (log files, InnoDB data files) and the MySQL database entering the running state. The instance is then shutdown by Connector/MXJ before the example terminates.
Connector/MXJ and Connector/J work together to enable you to
launch an instance of the mysqld
server
through the use of a keyword in the JDBC connection string.
Deploying Connector/MXJ within a Java application can be
automated through this method, making the deployment of
Connector/MXJ a simple process:
-
Download and unzip Connector/MXJ, add
connector-mxj.jar
to theCLASSPATH
. -
To the JDBC connection string, embed the
mxj
keyword, for example:jdbc:mysql:mxj://localhost:
PORT
/DBNAME
.
For more details, see Section 23.4.3, “Connector/MXJ Configuration”.
For deployment within a JBoss environment, you must configure the JBoss environment to use the Connector/MXJ component within the JDBC parameters:
-
Download Connector/MXJ copy the
connector-mxj.jar
file to the$JBOSS_HOME/server/default/lib
directory. -
Download Connector/J copy the
connector-mxj.jar
file to the$JBOSS_HOME/server/default/lib
directory. -
Create an MBean service xml file in the
$JBOSS_HOME/server/default/deploy
directory with any attributes set, for instance thedatadir
andautostart
. -
Set the JDBC parameters of your web application to use:
String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql:///test?propertiesTransform="+ "com.mysql.management.jmx.ConnectorMXJPropertiesTransform"; String user = "root"; String password = ""; Class.forName(driver); Connection conn = DriverManager.getConnection(url, user, password);
You may wish to create a separate users and database table spaces for each application, rather than using "root and test".
We highly suggest having a routine backup procedure for backing
up the database files in the datadir
.
The best way to ensure that your platform is supported is to run the JUnit tests. These will test the Connector/MXJ classes and the associated components.
The first thing to do is make sure that the components will
work on the platform. The
MysqldResource
class is really a
wrapper for a native version of MySQL, so not all platforms
are supported. At the time of this writing, Linux on the i386
architecture has been tested and seems to work quite well, as
does OS X v10.3. There has been limited testing on Windows and
Solaris.
Requirements:
-
JDK-1.4 or newer (or the JRE if you aren't going to be compiling the source or JSPs).
-
MySQL Connector/J version 5.0 or newer (from http://dev.mysql.com/downloads/connector/j/) installed and available via your CLASSPATH.
-
The
javax.management
classes for JMX version 1.2.1, these are present in the following application servers:-
JBoss - 4.0rc1 or newer.
-
Apache Tomcat - 5.0 or newer.
-
Sun's JMX reference implementation version 1.2.1 (from http://java.sun.com/products/JavaManagement/).
-
-
JUnit 3.8.1 (from http://www.junit.org/).
If building from source, All of the requirements from above, plus:
-
Ant version 1.5 or newer (download from http://ant.apache.org/).
-
The tests attempt to launch MySQL on the port 3336. If you have a MySQL running, it may conflict, but this isn't very likely because the default port for MySQL is 3306. However, You may set the "c-mxj_test_port" Java property to a port of your choosing. Alternatively, you may wish to start by shutting down any instances of MySQL you have running on the target machine.
The tests suppress output to the console by default. For verbose output, you may set the "c-mxj_test_silent" Java property to "false".
-
To run the JUnit test suite, the $CLASSPATH must include the following:
-
JUnit
-
JMX
-
Connector/J
-
MySQL Connector/MXJ
-
-
If
connector-mxj.jar
is not present in your download, unzip MySQL Connector/MXJ source archive.cd mysqldjmx ant dist
Then add
$TEMP/cmxj/stage/connector-mxj/connector-mxj.jar
to the CLASSPATH. -
if you have
junit
, execute the unit tests. From the command line, type:java junit.textui.TestRunner com.mysql.management.AllTestsSuite
The output should look something like this:
......................................... ......................................... .......... Time: 259.438 OK (101 tests)
Note that the tests are a bit slow near the end, so please be patient.
A feature of the MySQL Connector/J JDBC driver is the ability to specify a connection to an embedded Connector/MXJ instance through the use of the mxj keyword in the JDBC connection string.
In the following example, we have a program which creates a connection, executes a query, and prints the result to the System.out. The MySQL database will be deployed and started as part of the connection process, and shutdown as part of the finally block.
You can find this file in the Connector/MXJ package as
src/ConnectorMXJUrlTestExample.java
.
import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import com.mysql.management.driverlaunched.ServerLauncherSocketFactory; public class ConnectorMXJUrlTestExample { public static String DRIVER = "com.mysql.jdbc.Driver"; public static String JAVA_IO_TMPDIR = "java.io.tmpdir"; public static void main(String[] args) throws Exception { File ourAppDir = new File(System.getProperty(JAVA_IO_TMPDIR)); File databaseDir = new File(ourAppDir, "test-mxj"); int port = 3336; String url = "jdbc:mysql:mxj://localhost:" + port + "/test" + "?" + "server.basedir=" + databaseDir; System.out.println(url); String userName = "root"; String password = ""; Class.forName(DRIVER); Connection conn = null; try { conn = DriverManager.getConnection(url, userName, password); printQueryResults(conn, "SELECT VERSION()"); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { e.printStackTrace(); } ServerLauncherSocketFactory.shutdown(databaseDir, null); } } public static void printQueryResults(Connection conn, String SQLquery) throws Exception { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SQLquery); int columns = rs.getMetaData().getColumnCount(); System.out.println("------------------------"); System.out.println(); while (rs.next()) { for (int i = 1; i <= columns; i++) { System.out.println(rs.getString(i)); } System.out.println(); } rs.close(); stmt.close(); System.out.println("------------------------"); System.out.flush(); Thread.sleep(100); // wait for System.out to finish flush } }
To run the above program, be sure to have connector-mxj.jar and Connector/J in the CLASSPATH. Then type:
java ConnectorMXJTestExample
If you have a java application and wish to “embed” a MySQL database, make use of the com.mysql.management.MysqldResource class directly. This class may be instantiated with the default (no argument) constructor, or by passing in a java.io.File object representing the directory you wish the server to be "unzipped" into. It may also be instantiated with printstreams for "stdout" and "stderr" for logging.
Once instantiated, a java.util.Map, the object will be able to provide a java.util.Map of server options appropriate for the platform and version of MySQL which you will be using.
The MysqldResource enables you to "start" MySQL with a java.util.Map of server options which you provide, as well as "shutdown" the database. The following example shows a simplistic way to embed MySQL in an application using plain java objects.
You can find this file in the Connector/MXJ package as
src/ConnectorMXJObjectTestExample.java
.
import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.HashMap; import java.util.Map; import com.mysql.management.MysqldResource; public class ConnectorMXJObjectTestExample { public static String DRIVER = "com.mysql.jdbc.Driver"; public static String JAVA_IO_TMPDIR = "java.io.tmpdir"; public static void main(String[] args) throws Exception { File ourAppDir = new File(System.getProperty(JAVA_IO_TMPDIR)); File databaseDir = new File(ourAppDir, "mysql-mxj"); int port = 3336; MysqldResource mysqldResource = startDatabase(databaseDir, port); String userName = "root"; String password = ""; Class.forName(DRIVER); Connection conn = null; try { String url = "jdbc:mysql://localhost:" + port + "/test"; conn = DriverManager.getConnection(url, userName, password); printQueryResults(conn, "SELECT VERSION()"); } finally { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } try { mysqldResource.shutdown(); } catch (Exception e) { e.printStackTrace(); } } } public static MysqldResource startDatabase(File databaseDir, int port) { MysqldResource mysqldResource = new MysqldResource(databaseDir); Map database_options = new HashMap(); database_options.put("port", Integer.toString(port)); mysqldResource.start("test-mysqld-thread", database_options); if (!mysqldResource.isRunning()) { throw new RuntimeException("MySQL did not start."); } System.out.println("MySQL is running."); return mysqldResource; } public static void printQueryResults(Connection conn, String SQLquery) throws Exception { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SQLquery); int columns = rs.getMetaData().getColumnCount(); System.out.println("------------------------"); System.out.println(); while (rs.next()) { for (int i = 1; i <= columns; i++) { System.out.println(rs.getString(i)); } System.out.println(); } rs.close(); stmt.close(); System.out.println("------------------------"); System.out.flush(); Thread.sleep(100); // wait for System.out to finish flush } }
Of course there are many options we may wish to set for a MySQL database. These options may be specified as part of the JDBC connection string simply by prefixing each server option with ''server.''. In the following example we set two driver parameters and two server parameters:
String url = "jdbc:mysql://" + hostColonPort + "/" + "?" + "cacheServerConfiguration=true" + "&" + "useLocalSessionState=true" + "&" + "server.basedir=/opt/myapp/db" + "&" + "server.datadir=/mnt/bigdisk/myapp/data";
The MysqldResource
class supports three
different constructor forms:
-
public MysqldResource(File baseDir, File dataDir, String mysqlVersionString, PrintStream out, PrintStream err, Utils util)
The most detailed constructor, enables you to set the base directory, data directory, select a server by its version string, standard out and standard error and MySQL utilities class.
-
public MysqldResource(File baseDir, File dataDir, String mysqlVersionString, PrintStream out, PrintStream err)
Enables you to set the base directory, data directory, select a server by its version string, standard out and standard error.
-
public MysqldResource(File baseDir, File dataDir, String mysqlVersionString)
Enables you to set the base directory, data directory and select a server by its version string. Output for standard out and standard err are directed to System.out and System.err.
-
public MysqldResource(File baseDir, File dataDir)
Enables you to set the base directory and data directory. The default MySQL version is selected, and output for standard out and standard err are directed to System.out and System.err.
-
public MysqldResource(File baseDir);
Allows the setting of the "basedir" to deploy the MySQL files to. Output for standard out and standard err are directed to System.out and System.err.
-
public MysqldResource();
The basedir is defaulted to a subdirectory of the java.io.tempdir. Output for standard out and standard err are directed to System.out and System.err;
MysqldResource API includes the following methods:
-
void start(String threadName, Map mysqldArgs);
Deploys and starts MySQL. The "threadName" string is used to name the thread which actually performs the execution of the MySQL command line. The map is the set of arguments and their values to be passed to the command line.
-
void shutdown();
Shuts down the MySQL instance managed by the MysqldResource object.
-
Map getServerOptions();
Returns a map of all the options and their current (or default, if not running) options available for the MySQL database.
-
boolean isRunning();
Returns true if the MySQL database is running.
-
boolean isReadyForConnections();
Returns true once the database reports that is ready for connections.
-
void setKillDelay(int millis);
The default “Kill Delay” is 30 seconds. This represents the amount of time to wait between the initial request to shutdown and issuing a “force kill” if the database has not shutdown by itself.
-
void addCompletionListenser(Runnable listener);
Allows for applications to be notified when the server process completes. Each ''listener'' will be fired off in its own thread.
-
String getVersion();
Returns the version of MySQL.
-
void setVersion(int MajorVersion, int minorVersion, int patchLevel);
The standard distribution comes with only one version of MySQL packaged. However, it is possible to package multiple versions, and specify which version to use.
This section contains notes and tips on using the Connector/MXJ component within your applications.
If you want to create a custom Connector/MXJ package that
includes a specific mysqld
version or
platform then you must extract and rebuild the
connector-mxj.jar
file.
First, you should create a new directory into which you can
extract the current connector-mxj.jar
:
shell> mkdir custom-mxj shell> cd custom-mxj shell> jar -xf connector-mxj.jar shell> ls 5-0-22/ ConnectorMXJObjectTestExample.class ConnectorMXJUrlTestExample.class META-INF/ TestDb.class com/ kill.exe
The MySQL version directory, 5-0-22
in the
above example, contains all of the files used to create an
instance of MySQL when Connector/MXJ is executed. All of the
files in this directory are required for each version of MySQL
that you want to embed. Note as well the format of the version
number, which uses hyphens instead of periods to separate the
version number components.
Within the version specific directory are the platform specific
directories, and archives of the data
and
share
directory required by MySQL for the
various platforms. For example, here is the listing for the
default Connector/MXJ package:
shell>> ls Linux-i386/ META-INF/ Mac_OS_X-ppc/ SunOS-sparc/ Win-x86/ com/ data_dir.jar share_dir.jar win_share_dir.jar
Platform specific directories are listed by their OS and
platform - for example the mysqld
for Mac OS
X PowerPC is located within the
Mac_OS_X-ppc
directory. You can delete
directories from this location that you do not require, and add
new directories for additional platforms that you want to
support.
To add a platform specific mysqld
, create a
new directory with the corresponding name for your operating
system/platform. For example, you could add a directory for Mac
OS X/Intel using the directory
Mac_OS_X-i386
.
On Unix systems, you can determine the platform using
uname
:
shell> uname -p i386
Now you need to download or compile mysqld
for the MySQL version and platform you want to include in your
custom connector-mxj.jar
package into the
new directory.
Create a file called version.txt
in the
OS/platform directory you have just created that contains the
version string/path of the mysqld binary. For example:
mysql-5.0.22-osx10.3-i386/bin/mysqld
You can now recreate the connector-mxj.jar
file with the added mysqld
:
shell> cd custom-mxj shell> jar -cf ../connector-mxj.jar *
You should test this package using the steps outlined in Section 23.4.2.3, “Connector/MXJ Quick Start Guide”.
To include a pre-configured/populated database within your
Connector/MXJ JAR file you must create a custom
data_dir.jar
file, as included within the
main connector-mxj.jar
file:
-
First extract the
connector-mxj.jar
file, as outlined in the previous section (see Section 23.4.5.1, “Creating your own Connector/MXJ Package”). -
First, create your database and populate the database with the information you require in an existing instance of MySQL - including Connector/MXJ instances. Data file formats are compatible across platforms.
-
Shutdown the instance of MySQL.
-
Create a JAR file of the data directory and databases that you want to include your Connector/MXJ package. You should include the
mysql
database, which includes user authentication information, in addition to the specific databases you want to include. For example, to create a JAR of themysql
andmxjtest
databases:shell> jar -cf ../data_dir.jar mysql mxjtest
-
Copy the
data_dir.jar
file into the extractedconnector-mxj.jar
directory, and then create an archive forconnector-mxj.jar
.
Note that if you are create databases using the InnoDB engine,
you must include the ibdata.*
and
ib_logfile*
files within the
data_dir.jar
archive.
As a JMX MBean, MySQL Connector/MXJ requires a JMX v1.2 compliant MBean container, such as JBoss version 4. The MBean will uses the standard JMX management APIs to present (and allow the setting of) parameters which are appropriate for that platform.
If you are not using the SUN Reference implementation of the JMX libraries, you should skip this section. Or, if you are deploying to JBoss, you also may wish to skip to the next section.
We want to see the MysqldDynamicMBean in action inside of a JMX
agent. In the com.mysql.management.jmx.sunri
package is a custom JMX agent with two MBeans:
-
the MysqldDynamicMBean, and
-
a com.sun.jdmk.comm.HtmlAdaptorServer, which provides a web interface for manipulating the beans inside of a JMX agent.
When this very simple agent is started, it will allow a MySQL database to be started and stopped with a web browser.
-
Complete the testing of the platform as above.
-
current JDK, JUnit, Connector/J, MySQL Connector/MXJ
-
this section requires the SUN reference implementation of JMX
-
PATH
,JAVA_HOME
,ANT_HOME
,CLASSPATH
-
-
If not building from source, skip to next step
rebuild with the "sunri.present"
ant -Dsunri.present=true dist re-run tests: java junit.textui.TestRunner com.mysql.management.AllTestsSuite
-
launch the test agent from the command line:
java com.mysql.management.jmx.sunri.MysqldTestAgentSunHtmlAdaptor &
-
from a browser:
http://localhost:9092/
-
under MysqldAgent,
select "name=mysqld"
-
Observe the MBean View
-
scroll to the bottom of the screen press the startMysqld button
-
click
Back to MBean View
-
scroll to the bottom of the screen press stopMysqld button
-
kill the java process running the Test Agent (jmx server)
Once there is confidence that the MBean will function on the platform, deploying the MBean inside of a standard JMX Agent is the next step. Included are instructions for deploying to JBoss.
-
Ensure a current version of java development kit (v1.4.x), see above.
-
Ensure
JAVA_HOME
is set (JBoss requiresJAVA_HOME
) -
Ensure
JAVA_HOME/bin
is in thePATH
(You will NOT need to set your CLASSPATH, nor will you need any of the jars used in the previous tests).
-
-
Ensure a current version of JBoss (v4.0RC1 or better)
http://www.jboss.org/index.html select "Downloads" select "jboss-4.0.zip" pick a mirror unzip ~/dload/jboss-4.0.zip create a JBOSS_HOME environment variable set to the unzipped directory unix only: cd $JBOSS_HOME/bin chmod +x *.sh
-
Deploy (copy) the
connector-mxj.jar
to$JBOSS_HOME/server/default/lib
. -
Deploy (copy)
mysql-connector-java-3.1.4-beta-bin.jar
to$JBOSS_HOME/server/default/lib
. -
Create a
mxjtest.war
directory in$JBOSS_HOME/server/default/deploy
. -
Deploy (copy)
index.jsp
to$JBOSS_HOME/server/default/deploy/mxjtest.war
. -
Create a
mysqld-service.xml
file in$JBOSS_HOME/server/default/deploy
.<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="com.mysql.management.jmx.jboss.JBossMysqldDynamicMBean" name="mysql:type=service,name=mysqld"> <attribute name="datadir">/tmp/xxx_data_xxx</attribute> <attribute name="autostart">true</attribute> </mbean> </server>
-
Start jboss:
-
on unix: $JBOSS_HOME/bin/run.sh
-
on windows: %JBOSS_HOME%\bin\run.bat
Be ready: JBoss sends a lot of output to the screen.
-
-
When JBoss seems to have stopped sending output to the screen, open a web browser to:
http://localhost:8080/jmx-console
-
Scroll down to the bottom of the page in the
mysql
section, select the bulletedmysqld
link. -
Observe the JMX MBean View page. MySQL should already be running.
-
(If "autostart=true" was set, you may skip this step.) Scroll to the bottom of the screen. You may press the Invoke button to stop (or start) MySQL observe
Operation completed successfully without a return value.
ClickBack to MBean View
-
To confirm MySQL is running, open a web browser to
http://localhost:8080/mxjtest/
and you should see thatSELECT 1
returned with a result of
1
-
Guided by the
$JBOSS_HOME/server/default/deploy/mxjtest.war/index.jsp
you will be able to use MySQL in your Web Application. There is atest
database and aroot
user (no password) ready to experiment with. Try creating a table, inserting some rows, and doing some selects. -
Shut down MySQL. MySQL will be stopped automatically when JBoss is stopped, or: from the browser, scroll down to the bottom of the MBean View press the stop service Invoke button to halt the service. Observe
Operation completed successfully without a return value.
Usingps
ortask manager
see that MySQL is no longer running
As of 1.0.6-beta version is the ability to have the MBean start the MySQL database upon start up. Also, we've taken advantage of the JBoss life-cycle extension methods so that the database will gracefully shut down when JBoss is shutdown.
There are a wide variety of options available for obtaining support for using Connector/MXJ. You should contact the Connector/MXJ community for help before reporting a potential bug or problem. See Section 23.4.6.1, “Connector/MXJ Community Support”.
MySQL AB provides assistance to the user community by means of a number of mailing lists and web based forums.
You can find help and support through the MySQL and Java mailing list.
For information about subscribing to MySQL mailing lists or to browse list archives, visit http://lists.mysql.com/. See Section 1.7.1, “MySQL Mailing Lists”.
Community support from experienced users is also available through the MyODBC Forum. You may also find help from other users in the other MySQL Forums, located at http://forums.mysql.com. See Section 1.7.2, “MySQL Community Support at the MySQL Forums”.
If you encounter difficulties or problems with Connector/MXJ, contact the Connector/MXJ community Section 23.4.6.1, “Connector/MXJ Community Support”.
If reporting a problem, you should ideally include the following information with the email:
-
Operating system and version
-
Connector/MXJ version
-
MySQL server version
-
Copies of error messages or other unexpected output
-
Simple reproducible sample
Remember that the more information you can supply to us, the more likely it is that we can fix the problem.
If you believe the problem to be a bug, then you must report the bug through http://bugs.mysql.com/.