Error
Error Code:
3936
MySQL Error 3936: Invalid Character Set Specified
Description
This error indicates that the MySQL server encountered a character set name that it does not recognize or support. It commonly occurs when attempting to create a database or table, establish a connection, or modify a column's character set using an invalid or misspelled identifier in a SQL statement or configuration.
Error Message
Invalid character set '%s' was specified. It must be a character set name as supported by server.
Known Causes
3 known causesMisspelled Character Set Name
The specified character set name contains a typographical error, preventing the server from identifying it.
Character Set Not Supported
The character set specified is not available or supported by the particular MySQL server version or its current configuration.
Invalid Configuration Entry
A character set defined in a MySQL configuration file (e.g., my.cnf) is incorrect or unsupported, leading to errors during server startup or connection attempts.
Solutions
4 solutions available1. Verify Character Set Name and Server Support easy
Ensure the specified character set is valid and supported by your MySQL server.
1
Identify the exact character set name that is causing the error. It's usually present in the error message itself (e.g., '%s' in the error description).
2
Connect to your MySQL server using a client (like the `mysql` command-line client or MySQL Workbench).
3
Run the following SQL query to list all supported character sets on your server:
SHOW CHARACTER SET;
4
Compare the character set name from the error message with the list of supported character sets. If it's not present, you've found the issue.
5
Correct the character set name in your application code, configuration file, or SQL statement to one that is listed as supported.
2. Check MySQL Configuration for Default Character Set medium
Review and correct the default character set settings in your MySQL configuration file.
1
Locate your MySQL configuration file. Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or within the MySQL installation directory.
2
Open the configuration file in a text editor.
3
Look for the `[mysqld]` section and check for the following directives:
[mysqld]
character_set_server = ...
collation_server = ...
init_connect = ...
4
Ensure that the character set specified for `character_set_server` and `init_connect` (if present) is a valid and supported character set on your server. Use `SHOW CHARACTER SET;` as described in Solution 1 to confirm.
5
If an invalid character set is found, correct it to a supported one (e.g., `utf8mb4`).
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
init_connect = "SET NAMES utf8mb4";
6
Save the configuration file.
7
Restart the MySQL server for the changes to take effect.
sudo systemctl restart mysql
3. Specify Character Set at Connection Level easy
Explicitly set the character set when establishing a connection to the MySQL server.
1
Identify where your application or tool establishes a connection to the MySQL database.
2
Modify the connection string or parameters to include the character set. The exact syntax depends on your programming language or tool.
3
For example, in Python using `mysql.connector`, you might do:
import mysql.connector
cnx = mysql.connector.connect(
user='user',
password='password',
host='host',
database='database',
charset='utf8mb4'
)
4
Or in a connection string for JDBC:
jdbc:mysql://localhost:3306/mydatabase?characterEncoding=utf8mb4
5
Ensure the character set you specify here is supported by your MySQL server.
4. Update MySQL Server to Support Desired Character Set advanced
If a character set is genuinely needed but not supported, consider upgrading or recompiling MySQL.
1
Determine if the character set you need is a standard one that should be supported by recent MySQL versions. If it's a very old or custom character set, this might not be feasible.
2
Check your current MySQL server version: `SELECT VERSION();`
SELECT VERSION();
3
Consult the MySQL documentation for your specific version to see which character sets are supported and how to add or enable them.
4
If the character set is not supported in your current version, consider upgrading your MySQL server to a newer, more feature-rich version.
5
In rare cases, for extremely specific or custom character sets, you might need to recompile MySQL from source with the necessary character set support enabled. This is a complex process and should only be attempted by experienced administrators.