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.


MariaDB 10.1 shipped a few days ago, so it’s now a good time to focus on another important event. Last week we had a three day MariaDB developers meeting. It took place in Amsterdam (Oct 13-15). Meetings like this tend to have a great impact on the roadmap of the product. was very kind to offer their facilities for the developer meeting.

Thank you!

The day before the developer meeting there was a MySQL meetup arranged at eBay’s office in Amsterdam since, naturally, a lot of MariaDB developers were already in town for the developers meeting. The meetup was done in lightning talk style where developers went through cool features in MariaDB. It ended up being a packed meetup with about 50 participants that lasted for about 3.5 hours. Many talks, great discussions, good pizza, and drinks!

Thank you eBay!

Back to the MariaDB developers meeting. In the end 60+ persons attended the developer’s meeting and every day we had close to that amount of people present. The attendees came from 10 different companies/organizations. There definitely seems to be interest in these kinds of meetings.

The schedule for the developers meeting included sessions about upcoming features in MariaDB like window functions, new things in InnoDB and Spider, but also tools used in development. There were also separate tracks for MaxScale and Galera, in which both current state and roadmaps were presented and discussed.

A very active contributor to the MariaDB project, Daniel Black from OpenQuery, had a very good presentation including how MariaDB is becoming/should become more than a fork and things learned from the field. The slides from the presentation can be found here.

I myself tried to pull together what was discussed during the days in one of the finishing sessions called “MariaDB 10.2 roadmap”. The slides from my session are available on Speaker Deck.

Help us focus on the things that matter by voting on feature requests in MariaDB project tracking. A list of features for 10.2 ordered by most votes can be found here.

With the release of 10.1.8, MariaDB takes a next step. MariaDB 10.1 is now considered a stable release.

MariaDB 10.1 has a couple of main themes:

  • Security
  • High Availability
  • Scalability

During the last few years there have been many request for more security features in MariaDB. Actually it’s a trend in general. Since open source software is getting more attractive all the time, more functionality is wanted in areas where proprietary software typically has been leading. This is especially true for databases. In addition data privacy is a very hot topic.

The big new thing in security for MariaDB 10.1 is a complete data at rest encryption solution. The encryption that now is in use originates from Google’s encryption patch. It has now been migrated into MariaDB 10.1. The solution is fairly advanced, encrypting the actual data files on disk of course, but also all other places where data touches disk like the binlog in replication. It also introduces the concept of rolling encryption keys, where keys can be set to expire at some certain intervals causing data to be re-encrypted with new keys and becoming inaccessible with the old keys.

In addition to encryption, 10.1 also includes other security aspects like password validation with which one can define a scheme, for example with the popular cracklib library, against which new passwords are validated.

On the High Availability front there is a significant change. In 5.5 and 10.0 there are separate versions of MariaDB and MariaDB Galera Cluster. In 10.1 this has changed. There is only one MariaDB 10.1. It includes the cluster capabilities and they can just be switched on whenever needed.

In regards of scalability there are multiple aspects. On one hand the parallel slave replication introduced in MariaDB 10.0 is now further improved into what is called optimistic parallel replication. Very much simplified, this means that any INSERT/UPDATE/DELETE can be applied in parallel on the slave (even it wasn’t on the master) which in most cases will result in a performance gain.

When it comes to replication there is another very important compatibility aspect added to 10.1. MariaDB can now be a slave to MySQL 5.6 (or greater) also when MySQL 5.6 is configured to use GTID. This has been a highly voted feature request since users wants to be able to test MariaDB as part of their MySQL deployment. When migrating to MariaDB this functionality is also essential.

Another important aspect of scalability is that 10.1 includes a lot of performance improvements to perform better on CPUs with more processing power and more cores. Also on the disk IO side there are several improvements like page compression and defragmentation. Defragmentation is based on the patch developed first by Facebook and then further developed by Kakao Corp.

There are a lot of other new capabilities and improvements in MariaDB 10.1, like supporting new spatial reference systems and outputting explains in JSON. To get a complete list of new functionality please refer to the “What is MariaDB 10.1?” page.

Most important of all, go download MariaDB 10.1.8, install it, and start putting your workloads on it. Stay in contact with us by filing any findings that you think are wrong in Jira. You can also reach the developers of MariaDB on the #maria channel on Freenode IRC or email the developers by joining the mailing list maria-developers. Do enjoy!