Wiki source code of Configure MySQL

Last modified by Eleni Cojocariu on 2026/11/25 19:37

Show last authors
1 To use [[MySQL>>https://www.mysql.com/]] as XWiki's database, the database has to use the InnoDB storage engine and a UTF-8 character set with a binary collation, for the reasons given in [[MySQL Storage Engine and Character Set>>doc:documentation.xs.admin.installation.install-relational-database.configure-mysql.storage-engine-character-set.WebHome]]. If binary logging is enabled, it has to use the row-based or mixed format, because of the [[transaction isolation level>>doc:documentation.xs.admin.installation.install-relational-database.configure-mysql.transaction-isolation-level.WebHome]] XWiki uses.
2
3 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed.
4 1. Install [[MySQL>>https://dev.mysql.com/downloads/]] using whatever method suits your platform: a distribution package, MySQL's own installer, or a container image. See the [[Database support strategy>>dev:Community.SupportStrategy.DatabaseSupportStrategy]] for the supported versions.
5 1. Download the MySQL JDBC driver and copy it into the XWiki webapp's ##WEB-INF/lib## directory.(((
6 Get it from the [[MySQL Connector/J page>>https://www.mysql.com/downloads/connector/j/]] or from [[Maven Central>>https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/]], and use the latest version. The JAR file is named ##mysql-connector-j-*.jar##, from the {{code language="none"}}com.mysql:mysql-connector-j{{/code}} artifact.
7 )))
8 1. Create the ##xwiki## database with the required encoding. Log in as root with {{code language="none"}}mysql -u root -p{{/code}}, then run:(((
9 {{code language="none"}}
10 CREATE DATABASE xwiki CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
11 {{/code}}
12
13 The database may have another name, but that name must then also be set as the ##xwiki.db## property in the ##WEB-INF/xwiki.cfg## file, as described in [[the names of the database schemas>>Documentation.AdminGuide.Configuration.WebHome||anchor="HConfigurethenamesofdatabaseschemas"]].
14 )))
15 1. Create the ##xwiki## database user:(((
16 {{code language="none"}}
17 CREATE USER 'xwiki'@'localhost' IDENTIFIED BY 'xwiki';
18 {{/code}}
19
20 Outside an evaluation setup, replace ##'xwiki'## with a strong password.
21 )))
22 1. Grant that user privileges on every database:(((
23 {{code language="none"}}
24 GRANT ALL PRIVILEGES ON *.* TO 'xwiki'@'localhost';
25 FLUSH PRIVILEGES;
26 {{/code}}
27 )))
28 1. Configure XWiki to use MySQL. Open ##WEB-INF/hibernate.cfg.xml##, uncomment the MySQL configuration block, comment out the other database configurations, and set the connection values:(((
29 {{code language="xml"}}
30 <property name="hibernate.connection.url">jdbc:mysql://localhost/xwiki?useSSL=false</property>
31 <property name="hibernate.connection.username">xwiki</property>
32 <property name="hibernate.connection.password">xwiki</property>
33 <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
34 <property name="hibernate.dbcp.poolPreparedStatements">true</property>
35 <property name="hibernate.dbcp.maxOpenPreparedStatements">20</property>
36
37 <property name="hibernate.connection.charSet">UTF-8</property>
38 <property name="hibernate.connection.useUnicode">true</property>
39 <property name="hibernate.connection.characterEncoding">utf8</property>
40 {{/code}}
41
42 Adjust the host, port or database name if your setup differs, and configure SSL for a production environment.
43
44 {{version before="17.10.14, 18.4.6, 18.8.0"}}
45 Also add the following property, so that XWiki uses the [[READ COMMITTED transaction isolation level>>doc:documentation.xs.admin.installation.install-relational-database.configure-mysql.transaction-isolation-level.WebHome]]:
46
47 {{code language="xml"}}
48 <property name="hibernate.connection.isolation">2</property>
49 {{/code}}
50 {{/version}}
51 )))
52 1. Restart XWiki to apply the changes.
53 1. Open your wiki in a browser. XWiki connects to MySQL, creates its tables on the first start, and serves the wiki without a database error.

Get Connected