Resolving Database Collation & UTF-8 Encoding Issues in OJS
Comprehensive guide to solving character encoding, collation mismatches, and mojibake in OJS databases. Step-by-step SQL conversion scripts for utf8mb4.
Real Problem
Journals upgraded over multiple OJS generations frequently carry a toxic mix of latin1, utf8, and utf8mb4 tables, causing fatal upgrade crashes and corrupted multilingual abstracts.
Practical Solution
Systematically diagnose table and column character sets, convert legacy latin1/utf8 tables to utf8mb4_unicode_ci, and configure config.inc.php database connection encoding parameters.
The Anatomy of Character Encoding in Scholarly Databases
Academic research is inherently international. Abstracts, author names, and citation references frequently include German umlauts, French accents, Cyrillic typography, Arabic scripts, and complex mathematical formulas.
In older versions of OJS (such as 2.4.x and early 3.x), default installations often established MySQL databases with latin1_swedish_ci or incomplete 3-byte utf8 (utf8mb3). When modern Unicode characters were stored inside latin1 columns, MySQL either silently truncated the strings or stored them as double-encoded mojibake (e.g., displaying "é" instead of "é").
Diagnosing Mixed-Collation Corruption in MySQL
To inspect the current status of your database, run the following diagnostic SQL queries in MariaDB/MySQL:
SELECT table_name, table_collation
FROM information_schema.tables
WHERE table_schema = DATABASE()
GROUP BY table_collation, table_name;
To find individual text columns that deviate from the table standard:
SELECT table_name, column_name, character_set_name, collation_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND data_type IN ('varchar', 'text', 'longtext', 'mediumtext')
AND collation_name != 'utf8mb4_unicode_ci';
Automated Collation Conversion Protocol
Converting hundreds of tables manually is error-prone. You can dynamically generate conversion statements directly from the MySQL information_schema:
SELECT CONCAT('ALTER TABLE `', table_name, '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;')
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_type = 'BASE TABLE';
Export these statements, review them for any custom views, and execute them within a single administrative transaction.
Configuring config.inc.php for True Unicode Operation
Once the database engine and tables are unified under utf8mb4, OJS must be instructed to communicate with MariaDB using the matching charset.
Open config.inc.php and verify the [i18n] and [database] sections:
[i18n]
client_charset = "utf-8"
connection_charset = "utf8mb4"
database_charset = "utf8mb4"
In OJS 3.4 and 3.5, the database driver uses modern PDO/MySQLi parameters:
[database]
collation = "utf8mb4_unicode_ci"
Resolving Index Length Limits (Error 1071)
On older MySQL 5.7 instances, converting a VARCHAR(255) column to utf8mb4 can exceed the 767-byte InnoDB prefix limit (255 chars * 4 bytes = 1020 bytes). Ensure innodb_large_prefix is enabled or upgrade the database to MariaDB 10.6+ / MySQL 8.0 where the limit is natively 3072 bytes.
Step-by-Step Action Plan
Audit Table & Column Collations
Run diagnostic information_schema queries to identify tables using latin1 or mixed collations.
Backup Clean SQL Dump
Create a full database dump prior to any schema modification using mysqldump.
Generate Collation Conversion Script
Generate dynamic ALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4 queries for all OJS tables.
Execute Safe In-Place Conversion
Run the conversion queries, paying special attention to index length limits in older MySQL versions.
Update config.inc.php Connection Charset
Set connection_charset = utf8mb4 and collation = utf8mb4_unicode_ci in config.inc.php.
Questions People Usually Ask
What causes mojibake (double-encoded characters) in OJS?
Mojibake occurs when UTF-8 strings are written into a latin1 database connection, or when config.inc.php has client_charset = utf-8 while connection_charset is left off or mismatched.
Why does an OJS upgrade crash on foreign key constraints when collations differ?
MySQL strictly forbids foreign key relationships between columns that have different character sets or collations. If submissions.submission_id is utf8mb4 but publication_settings.submission_id is latin1, the migration halts with Error 1215: Cannot add foreign key constraint.
Is utf8mb4 strictly required for modern OJS 3.4 and 3.5?
Yes. Modern OJS versions mandate utf8mb4 to support full 4-byte Unicode characters, emojis, advanced mathematical notations, and Asian ideograms.
Suffering from Garbled Characters in OJS?
AcademiaTech repairs corrupted database character sets, converts legacy tables to utf8mb4, and cleans up distorted scholarly metadata.