MariaDB Connector/J has evolved a lot during the year. In this post I will talk about the failover capabilities in the connector and give some guidance on how to use them in some certain cases. One other important new feature that I’ll cover in a later article is the fact that MariaDB Connector/J can do load balancing over several servers now as well.

To start off with we’ll need the connector itself. Do either of the following to get version 1.2.3 of MariaDB Connector/J which is the newest stable version as of writing:

  • Download the binary from (requires login) . Look for Connectors / Java on the download page once logged in.
  • The connector is also available through Maven. To instruct Maven to include the MariaDB Connector/J add the following dependency to your application’s pom.xml file:

The failover support added to MariaDB Connector/J can be used in several high availability scenarios:

  1. The most typical one, where normal MariaDB or MySQL replication is used and the setup consists of one master host for write operations and several slave hosts for the read operations.
  2. Multi-master setups, such as MariaDB Galera Cluster, where every host is a master
  3. Support for Amazon Aurora and its automatic failover functionality
  4. The connector also supports having several masters in a normal replication topology as described in 1, but the connector will be unaware of the differences between the masters and will just pick one according to the order in which the masters have been given in the JDBC URL.

To demonstrate the failover capability I will focus on scenario 3) and set up an Amazon Aurora cluster and use Connector/J to connect to it and simulate a failover in the cluster to see how the connector reacts to that. In case you want to know more about Aurora please refer to its documentation.

To start off with I’ll create one Aurora instance that will act as the master node for the cluster:

  • To find Aurora, go to your AWS console, click on RDS under Databases and you should see a button saying “Launch an Aurora DB instance”. Click on it.
  • Type in the requested information on the Specify DB Details -page. Notice that when you move between the fields there is a good explanation of the field appearing on the right hand side. Once done click “Next Step”
  • On the “Configure Advanced Settings” the first part is important. Choose VPC and VPC subnet group or create a new VPC. In the VPC Security Group(s) select the VPC security groups that should be able to connect to the Aurora cluster.

Once done you should have one node of Aurora up and running looking like this:

AWS Console -RDS Aurora

You’ll notice that it says “Writer” in the Replication Role column of the above table.

Let’s add a slave to this master. A slave is called a replica within the Aurora cluster:

  1. To do that click in the checkbox next to the instance in the table above. It will expand the row and you should see a “Instance Actions” button. Click on it and choose “Create Aurora Replica”.
  2. On the next “Create Aurora Replica” page you’ll have to fill in the “DB Instance Identifier*” field. Other than that you can go with the default ones if you don’t want to change any of the default values. Finally hit the “Create Aurora Replica” button.

Repeat the above steps for the amount of replicas you want for your cluster. The maximum amount is 15.

Once done you should have an instance table looking like this:

AWS Console RDS Aurora multiple


The failover documentation for MariaDB Connector/J failover can be found here and the start page of the full documentation for the connector here.

Failover example for Aurora

Next, let’s write a program that uses the failover capabilities of the MariaDB connector. Below you’ll see the Java class TestConnection. Take a moment and read through the code. It’s pretty straightforward and should be easy to follow.

The important step in the above example Java program is where the URL is specified:

By giving the keyword aurora in jdbc:mysql:aurora:// we instruct the driver that it should take Aurora failover support into use. Next in the url the three servers are given, aurora-demo-1…, aurora-demo-2… and aurora-demo-3 and finally the username and the password.

RDS AWS Console details

Make sure to use instance endpoint (in green) and not cluster endpoint (in red).

If we run the program it will start outputting rows with about 1 second interval looking like this:
16:15:22.467 connected-to:aurora-demo-2 master:aurora-demo-2 slave:aurora-demo-1,aurora-demo-3
16:15:23.579 connected-to:aurora-demo-2 master:aurora-demo-2 slave:aurora-demo-1,aurora-demo-3

First a time indicator, then to which server the connection points currently and then which server is master and which is slave from INFORMATION_SCHEMA. This data in the INFORMATION_SCHEMA is Aurora specific and doesn’t exist for MariaDB or MySQL.

The more interesting part is when we keep the program running and a failover occurs in the Aurora cluster, i.e. the slave becomes the master. Then the output would look like this:
20:56:49.241 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
20:56:50.370 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
20:56:51.501 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
20:56:52.637 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
20:58:19.374 connected-to:aurora-demo-2 master:aurora-demo-2 slave:aurora-demo-1,aurora-demo-3
20:58:20.481 connected-to:aurora-demo-2 master:aurora-demo-2 slave:aurora-demo-1,aurora-demo-3
20:58:21.587 connected-to:aurora-demo-2 master:aurora-demo-2 slave:aurora-demo-1,aurora-demo-3

The interesting rows are highlighted. While running the small java program I forced a failover in the Aurora cluster. As you see the program then waits for a while until it gets a new master connection and then continues. As you can see the original slave aurora-demo-2 has become the master to which also the connections are established after the failover. The only thing visible from application point of view is that there will be a delay until the server responds again.That’s automatic failover!

If the new master’s election would have taken more than 120 seconds (the default value of failoverLoopRetries -parameter), the connector would have thrown an SQLException. There are more parameters with which the failover capabilities can be tuned to meet your needs. You can find them in the documentation.

Failover on slaves for Aurora

MariaDB Connector/J has 2 underlying connections when using failover with either “replication” or in this case the ”aurora” parameter; one connection to master and one to a slave. Using the previous program with a parameter “true”, the driver will use the slave connection.

The output looks like this when suddenly rebooting a slave instance that is in use:
16:27:24.524 connected-to:aurora-demo-3 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:25.638 connected-to:aurora-demo-3 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:26.759 connected-to:aurora-demo-3 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:27.982 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:29.089 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:30.196 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:31.310 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:32.435 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:33.542 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:34.649 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:35.757 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:36.872 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:37.982 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:39.089 connected-to:aurora-demo-1 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:40.200 connected-to:aurora-demo-2 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:41.301 connected-to:aurora-demo-2 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:42.406 connected-to:aurora-demo-2 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3
16:27:43.522 connected-to:aurora-demo-2 master:aurora-demo-1 slave:aurora-demo-2,aurora-demo-3

The driver that was using a connection to the slave aurora-demo-3 switch immediately to the connection to the master aurora-demo-1. When a new slave connection (to aurora-demo-2) is established, the driver will switch another time the connection.

Load-balancing and other capabilities

MariaDB Connector/J also includes load balancing, execution of prepared statements on server side and other interesting new features that I will cover in upcoming blog posts. For properly testing load balancing I’ll set up a connection pool.

Connectors now available to the MySQL® community as part of the MariaDB open source project

Helsinki – November 29, 2012 – Monty Program, the home of MariaDB, owned by MySQL®-database-creator Monty Widenius and its employees, and SkySQL, the trusted provider of open source database solutions, today announced the immediate availability of their connectors, ‘MariaDB Client Library for C and MariaDB Client Library for Java Applications’, to the wider MySQL® database community in the permissive LGPL licence.

With this announcement, the connectors become part of the wider MariaDB open source project, to which users will be able to contribute via relevant online resources.

Good news for open source developers

This announcement is relevant for users involved with applications built in C or Java language that also make use of a MariaDB and/or MySQL database, as these require a connector to ensure that the applications & the databases can talk to each other.

News Highlights

As part of their ongoing efforts to contribute innovation and technology to the wider MySQL database and open source user communities, Monty Program & SkySQL  today announced the availability of the MariaDB Client Library for C and MariaDB Client Library for Java Applications.

Up until recently, the two companies had been working on the connectors as a joint internal project used for specific customer requirements and they are now making their connectors generally available to the community as part of the MariaDB open source project.

Connectors enable users to connect from a given application to a database, in this case the MySQL & MariaDB databases. Commercial maintenance & support for the servers and connectors will be available via SkySQL’s Enterprise Data Suite.

Download links & additional resources

Supporting quotes:

“These connectors have been an internal SkySQL/Monty Program project long enough and it was time to make them available to the wider MySQL user community,” said Monty Widenius, CEO of Monty Program. “The connectors will add value to the MariaDB project by making our database technology and the MariaDB project itself easier for everyone to use. If anything, we’re opening the MariaDB project even further to the community and demonstrating that innovation happens with MariaDB.”

 “We’ve been seeing a strong demand for connectors from the MySQL database ecosystem. We are looking for means to ensure that the ecosystem prospers and that both users and developers have a rich set of options. We believe that these connectors will help to stimulate innovation in the ecosystem,” added Patrik Sallner, CEO of SkySQL. “Helping organisations out there adopt the MySQL and MariaDB databases more easily for their software projects also reinforces our position as the one-stop shop for all things to do with the MySQL and MariaDB databases.”

About SkySQL

SkySQL is the trusted provider of open source database solutions for MySQL and MariaDB users – in the enterprise and cloud, providing over 300 enterprise customers including Canal+, ClubMed, Constant Contact, Deutsche Telekom, La Poste, Virgin Mobile, Western Digital and XING with database deployment and management solutions.

With 250+ years of original MySQL experience, SkySQL has the leading MySQL talent pool with sponsorship by the original MySQL and MariaDB creators. It has also developed cloud-based database management solutions that bring ease of use, while providing an effective way to increase database productivity both in the enterprise and the cloud.

For more information, please visit, and follow the company’s conversations on Twitter and Facebook.

About Monty Program

Monty Program Ab was founded by Michael “Monty” Widenius, the founder and creator of MySQL®. Monty Program is a center of engineering excellence for MariaDB, the Aria storage engine, MySQL®, and other associated technologies.

More than half of our staff are full-time developers, including most of the original MySQL engineers, some new personnel, and Monty. We have a better knowledge of the core MySQL® code than any other company! We are well funded and all of our plans and strategies take a long-term view.

For more information, visit:



MySQL is a registered trademark of Oracle and/or its affiliates.

MariaDB is a registered trademark of Monty Program Ab.

SkySQL and the SkySQL logo are trademarks of SkySQL Inc. or SkySQL Ab. Neither SkySQL nor Monty Program is affiliated with MySQL or Oracle. All other company and product names may be trademarks or service marks of their respective owners.