Error
Error Code:
1115
MariaDB Error 1115: Unknown Character Set Specified
Description
This error indicates that MariaDB does not recognize or support the character set name provided in a query or configuration. It commonly occurs when creating databases, tables, or establishing connections, preventing the operation from completing successfully.
Error Message
Unknown character set: '%s'
Known Causes
4 known causesTypo in Character Set Name
A character set name was misspelled, or an incorrect alias was used when defining a database, table, or connection parameter.
Unsupported Character Set
The specified character set is not recognized or supported by your current MariaDB server version or build configuration.
Missing Character Set Plugin
For certain less common character sets, a required plugin or module may not be loaded or installed on the MariaDB server.
Client-Server Miscommunication
The client application is attempting to use a character set for communication that the MariaDB server does not understand.
Solutions
4 solutions available1. Correcting the Character Set in Your SQL Statement easy
Identify and correct the misspelled or unsupported character set name directly within your SQL query.
1
Examine the SQL statement that triggered the 'Unknown character set' error. Look for the `CHARACTER SET` clause.
Example of a statement that might cause this error:
CREATE TABLE my_table (col1 VARCHAR(255)) DEFAULT CHARACTER SET 'utf8mb4_general_ci_typo';
2
Verify the spelling and validity of the character set name. Common typos include extra characters, incorrect underscores, or invalid variations.
Corrected example:
CREATE TABLE my_table (col1 VARCHAR(255)) DEFAULT CHARACTER SET 'utf8mb4';
-- Or a more specific collation if needed:
CREATE TABLE my_table (col1 VARCHAR(255)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3
If you intended to use a specific collation, ensure it's valid for the chosen character set. You can list available character sets and collations with `SHOW CHARACTER SET;` and `SHOW COLLATION;`.
SHOW CHARACTER SET;
SHOW COLLATION;
2. Setting the Default Character Set for a Database medium
Modify the database's default character set to a supported one, preventing future errors for new objects.
1
Connect to your MariaDB server using a client like `mysql` or `mariadb`.
mariadb -u your_user -p
2
Select the database for which you want to change the default character set.
USE your_database_name;
3
Alter the database to set a valid default character set. `utf8mb4` is generally recommended for broad compatibility.
ALTER DATABASE your_database_name DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
4
Verify the change by checking the database's information schema.
SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'your_database_name';
3. Configuring MariaDB Server Defaults medium
Update the MariaDB server configuration file to set global default character set and collation.
1
Locate your MariaDB configuration file. Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or a file within `/etc/mysql/conf.d/`.
Example: find / -name my.cnf 2>/dev/null
2
Open the configuration file with a text editor (e.g., `nano`, `vim`). You'll likely need root privileges.
sudo nano /etc/my.cnf
3
Add or modify the `character-set-server` and `collation-server` settings under the `[mysqld]` section. Ensure the character set is valid.
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
4
Save the changes and restart the MariaDB service for the new configuration to take effect.
sudo systemctl restart mariadb
5
After restarting, connect to MariaDB and check the server status to confirm the new defaults.
SHOW VARIABLES LIKE 'character_set_server';
SHOW VARIABLES LIKE 'collation_server';
4. Updating Client Connection Character Set easy
Ensure your client application or tool is configured to use a supported character set when connecting to MariaDB.
1
Identify the character set setting in your client application or connection string.
Example in a Python script using mariadb-connector:
import mariadb
try:
conn = mariadb.connect(
user="your_user",
password="your_password",
host="your_host",
database="your_database",
charset="utf8mb4" # Ensure this is a valid charset
)
print("Connected successfully")
except mariadb.Error as e:
print(f"Error connecting to MariaDB: {e}")
2
Consult the documentation for your specific client tool (e.g., MySQL Workbench, DBeaver, command-line client) to find where to set the character set.
For the `mariadb` command-line client, you can use the `--default-character-set` option:
mariadb -u your_user -p --default-character-set=utf8mb4
3
Ensure the character set specified in the client matches a supported character set on the MariaDB server.
Run `SHOW CHARACTER SET;` on your MariaDB server to list available character sets.