diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index b0a07c71b2..6a0160753d 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -1543,6 +1543,10 @@ Connect to an SAP MaxDB database server.
+
Connect to a MySQL database server.
+
+* `MARIADB`
++
+Connect to a MariaDB database server.
++
* `ORACLE`
+
Connect to an Oracle database server.
diff --git a/Documentation/database-setup.txt b/Documentation/database-setup.txt
index 8667f43f4d..3fd0c919e3 100644
--- a/Documentation/database-setup.txt
+++ b/Documentation/database-setup.txt
@@ -74,6 +74,14 @@ rights on it:
Visit MySQL's link:http://dev.mysql.com/doc/[documentation] for further
information regarding using MySQL.
+[[createdb_mariadb]]
+=== MariaDB
+
+Refer to MySQL section above how to create MariaDB database.
+
+Visit MariaDB's link:https://mariadb.com/kb/en/mariadb/[documentation] for further
+information regarding using MariaDB.
+
[[createdb_oracle]]
=== Oracle
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/DatabaseConfigModule.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/DatabaseConfigModule.java
index 45206c9fdd..b80bf35d88 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/DatabaseConfigModule.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/DatabaseConfigModule.java
@@ -39,6 +39,9 @@ public class DatabaseConfigModule extends AbstractModule {
bind(DatabaseConfigInitializer.class)
.annotatedWith(Names.named("jdbc"))
.to(JDBCInitializer.class);
+ bind(DatabaseConfigInitializer.class)
+ .annotatedWith(Names.named("mariadb"))
+ .to(MariaDbInitializer.class);
bind(DatabaseConfigInitializer.class)
.annotatedWith(Names.named("mysql"))
.to(MySqlInitializer.class);
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitDatabase.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitDatabase.java
index 5565158873..349ab55c97 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitDatabase.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitDatabase.java
@@ -85,6 +85,8 @@ class InitDatabase implements InitStep {
if (dci instanceof MySqlInitializer) {
libraries.mysqlDriver.downloadRequired();
+ } else if (dci instanceof MariaDbInitializer) {
+ libraries.mariadbDriver.downloadRequired();
} else if (dci instanceof OracleInitializer) {
libraries.oracleDriver.downloadRequired();
} else if (dci instanceof DB2Initializer) {
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/JDBCInitializer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/JDBCInitializer.java
index 4659ee3f79..e3a1d666a0 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/JDBCInitializer.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/JDBCInitializer.java
@@ -37,6 +37,8 @@ class JDBCInitializer implements DatabaseConfigInitializer {
database.set("driver", "org.apache.derby.jdbc.EmbeddedDriver");
} else if (url.startsWith("jdbc:h2:")) {
database.set("driver", "org.h2.Driver");
+ } else if (url.startsWith("jdbc:mariadb:")) {
+ database.set("driver", "org.mariadb.jdbc.Driver");
} else if (url.startsWith("jdbc:mysql:")) {
database.set("driver", "com.mysql.jdbc.Driver");
} else if (url.startsWith("jdbc:postgresql:")) {
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/Libraries.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/Libraries.java
index 526f17204e..3259f96799 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/Libraries.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/Libraries.java
@@ -43,6 +43,7 @@ class Libraries {
/* final */ LibraryDownloader db2Driver;
/* final */ LibraryDownloader db2DriverLicense;
/* final */ LibraryDownloader hanaDriver;
+ /* final */ LibraryDownloader mariadbDriver;
/* final */ LibraryDownloader mysqlDriver;
/* final */ LibraryDownloader oracleDriver;
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/MariaDbInitializer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/MariaDbInitializer.java
new file mode 100644
index 0000000000..db32113358
--- /dev/null
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/MariaDbInitializer.java
@@ -0,0 +1,32 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.pgm.init;
+
+import static com.google.gerrit.pgm.init.api.InitUtil.username;
+
+import com.google.gerrit.pgm.init.api.Section;
+
+class MariaDbInitializer implements DatabaseConfigInitializer {
+
+ @Override
+ public void initConfig(Section databaseSection) {
+ final String defPort = "(mariadb default)";
+ databaseSection.string("Server hostname", "hostname", "localhost");
+ databaseSection.string("Server port", "port", defPort, true);
+ databaseSection.string("Database name", "database", "reviewdb");
+ databaseSection.string("Database username", "username", username());
+ databaseSection.password("username", "password");
+ }
+}
diff --git a/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/init/libraries.config b/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/init/libraries.config
index f4564f5aa2..26ac9d6b01 100644
--- a/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/init/libraries.config
+++ b/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/init/libraries.config
@@ -18,6 +18,12 @@
sha1 = b0878056f15616989144d6114d36d3942321d0d1
remove = mysql-connector-java-.*[.]jar
+[library "mariadbDriver"]
+ name = MariaDB Connector/J 1.5.9
+ url = https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.9/mariadb-java-client-1.5.9.jar
+ sha1 = 75d4d6e4cdb9a551a102e92a14c640768174e214
+ remove = mariadb-java-client-.*[.]jar
+
[library "oracleDriver"]
name = Oracle JDBC driver 11g Release 2 (11.2.0)
url = file:///u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/DataSourceModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/DataSourceModule.java
index 65843d8fbb..ee57c8bf75 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/DataSourceModule.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/DataSourceModule.java
@@ -25,6 +25,7 @@ public class DataSourceModule extends AbstractModule {
bind(DataSourceType.class).annotatedWith(Names.named("derby")).to(Derby.class);
bind(DataSourceType.class).annotatedWith(Names.named("h2")).to(H2.class);
bind(DataSourceType.class).annotatedWith(Names.named("jdbc")).to(JDBC.class);
+ bind(DataSourceType.class).annotatedWith(Names.named("mariadb")).to(MariaDb.class);
bind(DataSourceType.class).annotatedWith(Names.named("mysql")).to(MySql.class);
bind(DataSourceType.class).annotatedWith(Names.named("oracle")).to(Oracle.class);
bind(DataSourceType.class).annotatedWith(Names.named("postgresql")).to(PostgreSQL.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/MariaDb.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/MariaDb.java
new file mode 100644
index 0000000000..ed18a869ac
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/MariaDb.java
@@ -0,0 +1,54 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.schema;
+
+import static com.google.gerrit.server.schema.JdbcUtil.hostname;
+import static com.google.gerrit.server.schema.JdbcUtil.port;
+
+import com.google.gerrit.server.config.ConfigSection;
+import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.inject.Inject;
+import org.eclipse.jgit.lib.Config;
+
+class MariaDb extends BaseDataSourceType {
+ private final Config cfg;
+
+ @Inject
+ MariaDb(@GerritServerConfig Config cfg) {
+ super("org.mariadb.jdbc.Driver");
+ this.cfg = cfg;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder b = new StringBuilder();
+ ConfigSection dbs = new ConfigSection(cfg, "database");
+ b.append("jdbc:mariadb://");
+ b.append(hostname(dbs.optional("hostname")));
+ b.append(port(dbs.optional("port")));
+ b.append("/");
+ b.append(dbs.required("database"));
+ return b.toString();
+ }
+
+ @Override
+ public boolean usePool() {
+ // MariaDB has given us trouble with the connection pool,
+ // sometimes the backend disconnects and the pool winds
+ // up with a stale connection. Fortunately opening up
+ // a new MariaDB connection is usually very fast.
+ return false;
+ }
+}
diff --git a/gerrit-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit.xml b/gerrit-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit.xml
index 3ae9440e41..02aa1b9724 100644
--- a/gerrit-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit.xml
+++ b/gerrit-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit.xml
@@ -49,6 +49,10 @@
com.mysql.jdbc.Driver
jdbc:mysql://localhost/reviewdb?user=gerrit2&password=secretkey
-->
+