MySQL Storage Engine and Character Set
Explanation
XWiki's Hibernate store makes two assumptions about the MySQL schema it is given: that its tables are transactional, and that its character set can hold any character a user may type. Both are decided when the database is created and are awkward to change afterwards, which is why Configure MySQL creates the database with an explicit storage engine and character set instead of accepting MySQL's defaults.
Storage engine
XWiki must run on InnoDB, MySQL's transactional storage engine.
Every write XWiki performs is wrapped in a transaction. When a save fails halfway through, the store rolls that transaction back and the database returns to its last known good state. A storage engine without transaction support accepts the rollback and does nothing: the half-applied write stays, and the wiki keeps a document whose parts disagree with each other. Nothing reports this when it happens; it surfaces later as pages that can no longer be loaded or saved.
XWiki also inspects its tables through InnoDB's own metadata tables in information_schema, so the store's checks on how a table is stored return nothing at all for a table held by another engine.
InnoDB is the default engine on every supported MySQL version, so a database created today already complies. Only a database inherited from an old installation is worth checking, and Convert MyISAM Tables to InnoDB converts in place whatever it still holds on the old engine.
Character set and collation
XWiki expects the utf8mb4 character set with the utf8mb4_bin collation. That pair is a requirement, not a preference, and MySQL's utf8 is the trap next to it: utf8 is an alias for utf8mb3, which stores at most three bytes per character and therefore cannot store a four-byte character at all. Those four-byte characters are the ones users reach for most visibly, an emoji in a page title, in page content or in a comment, and on utf8mb3 they are rejected or mangled rather than saved. utf8mb4 is the character set that holds them, and utf8mb4_bin is the collation XWiki uses for its own databases and runs its functional tests against. MySQL 8 already defaults to utf8mb4, but not to the binary collation.
Getting the main wiki's database right is also what makes every later subwiki right. When XWiki creates the database of a new subwiki, it reads the main wiki's character set and collation and creates the subwiki with the same pair, so a main database left on utf8mb3 passes that limitation on to every subwiki created after it, each of which then has to be converted on its own.
Setting the character set and collation per database, as the installation procedure does, is enough. Setting them on the server instead makes every database that anyone creates comply by default, it is what XWiki's own functional tests do when they start their MySQL container:
character-set-server=utf8mb4
collation-server=utf8mb4_binThe database is only half of the path a character travels. The other half is the JVM running XWiki's servlet container, and on Java 17 the JVM's default encoding still follows the platform locale. If that locale is not UTF-8, characters are stored wrongly whatever the database is set to, so start the servlet container with:
-Dfile.encoding=utf8The Tomcat packages of most Linux distributions already set it, but not all of them, so it is worth confirming. On Java 18 and later the flag is a no-op, since UTF-8 became the JVM's default encoding.
An existing database on the wrong character set does not have to be rebuilt: Convert a MySQL Database to utf8mb4 converts it, its tables and its columns in place.