Skip to content

Error code 1366 in MySQL typically means there’s a mismatch between the character set of the input data and that defined in the table schema. This issue often occurs during data insertion or updating, leading to a failure in properly storing or retrieving the data.mysql error 1366

What is error code 1366?

Error 1366, often stated as “Incorrect string value,” indicates that MySQL cannot correctly process the given string due to character set incompatibility. This issue is prevalent when dealing with non-latin characters in a database that is not set up to handle them.

Check your database and table character set

Before proceeding to fix the error, it’s essential to understand the character set used by your database and tables.

SHOW CREATE DATABASE your_database_name;
SHOW CREATE TABLE your_table_name;

These commands will display the character set and collation for your database and table. If they are not set to a character set that supports your data (like utf8mb4 for Unicode), this could be the cause of the error.

Update database and table character sets

If the character set is the issue, you can alter your database and tables to use a more appropriate one, such as utf8mb4.

ALTER DATABASE your_database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Modify column character set

In some cases, you might need to change the character set of specific columns rather than the entire table.

ALTER TABLE your_table_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Connection character set

Ensure that the connection character set matches the character set of your database. This can be done by setting the character set at the beginning of your session.

SET NAMES 'utf8mb4';

Check client and server settings

Sometimes, the client or server settings can override your database settings. Check these settings to ensure they are not causing the issue.

SHOW VARIABLES LIKE 'character_set_client';
SHOW VARIABLES LIKE 'character_set_server';

Correct data already in the database

If incorrect data has already been inserted, you might need to export, convert, and re-import the data. Tools like mysqldump can be helpful for this process.

Handling error 1366 in stored procedures and triggers

If you encounter this error in stored procedures or triggers, ensure that the character set is declared correctly within these elements.

Monitor and preventing future issues

Regularly monitor your database and application logs for error 1366. Implementing input validation in your application to ensure data compatibility with your database’s character set can prevent future occurrences of this issue.

Conclusion

During troubleshooting, Basedash helps teams move faster by combining AI-assisted analysis with direct SQL access, so you can validate fixes, monitor results, and share clear dashboards after incidents are resolved.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.