How to fix ERROR 1300: Invalid character string in MySQL
MySQL ERROR 1300 occurs when the database encounters character data that doesn't conform to the expected character set encoding, typically during data import or string operations. This error is resolved by aligning character set configurations and ensuring your data uses the correct encoding.
Quick fix
Fixes 1300
-- Check database character set
SHOW CREATE DATABASE `your_database`;
-- Check table character sets
SHOW CREATE TABLE `your_table`;
-- Check all character set variables
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';- Verify character set configuration of your database and tables
- Convert to utf8mb4 character set if needed
- Use mysqlimport instead of LOAD DATA INFILE with character set flag
- Clean source data to remove invalid characters
-- Check database character setSHOW CREATE DATABASE `your_database`;-- Check table character setsSHOW CREATE TABLE `your_table`;-- Check all character set variablesSHOW VARIABLES LIKE 'character_set%';SHOW VARIABLES LIKE 'collation%';ERROR 1300: Invalid character string
What this error means
MySQL ERROR 1300 (ER_INVALID_CHARACTER_STRING) is raised when MySQL detects an invalid character sequence for a specific character set. This happens most commonly when: 1. Character data contains multi-byte sequences that don't conform to UTF-8 or the specified character set encoding. 2. A character set mismatch exists between the table/column definition and the actual data being inserted or imported. 3. The MySQL utf8/utf8mb3 character set (which only supports 3-byte characters) encounters 4-byte UTF-8 characters like emojis or certain Unicode characters. The error typically appears during data import operations (LOAD DATA INFILE, mysqldump restore) or when inserting data with incompatible character encoding. It prevents the database from accepting data it cannot properly store or interpret.
Typical symptoms
- LOAD DATA INFILE fails with ERROR 1300 when importing CSV or text files
- Database dump import fails partway through the restoration process
- INSERT or UPDATE statements fail with invalid character string warnings
- MySQL Workbench shows errors during data import or schema restoration
- Migration tools or ETL processes fail when loading data into MySQL tables
Common causes
- UTF-8 4-byte characters (emojis, certain CJK characters) in utf8mb3 columns that only support 3-byte characters
- Character set mismatch between the source data encoding and target table/column collation
- Mixed or corrupted encoding in source files where some characters are valid but others are malformed
- Escape character issues in LOAD DATA INFILE followed by multi-byte characters
- MySQL version upgrades that changed default character sets without updating existing schemas
- Binary or non-Unicode control characters in source data that the specified character set cannot represent
How to fix "ERROR 1300: Invalid character string"
Check what character sets are currently configured to identify mismatches:
-- Check database character set
SHOW CREATE DATABASE `your_database`;
-- Check table character sets
SHOW CREATE TABLE `your_table`;
-- Check all character set variables
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';Look for tables using utf8 or utf8mb3 instead of utf8mb4. The utf8mb3 character set cannot store 4-byte UTF-8 sequences.
MySQL 8.0 should default to utf8mb4, but older versions may default to utf8mb3. If your tables use utf8 or utf8mb3, upgrade them:
-- Convert database to utf8mb4
ALTER DATABASE `your_database` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Convert specific table
ALTER TABLE `your_table` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Convert specific column
ALTER TABLE `your_table` MODIFY `column_name` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;utf8mb4 fully supports all UTF-8 characters including 4-byte sequences.
For bulk data import, mysqlimport provides better character set handling:
mysqlimport \
--default-character-set=utf8mb4 \
--user=your_user \
--password \
your_database \
data_file.txtThe --default-character-set=utf8mb4 flag works reliably with mysqlimport. If using LOAD DATA INFILE directly, specify the character set:
LOAD DATA INFILE '/path/to/file.csv'
INTO TABLE `your_table`
CHARACTER SET utf8mb4
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';If the source file contains corrupt or invalid character sequences, preprocess it:
# Remove non-UTF-8 characters (Linux/Mac)
iconv -f UTF-8 -t UTF-8 -c input_file.csv > cleaned_file.csv
# Remove control characters
sed 's/[[:cntrl:]]//g' input_file.csv > cleaned_file.csv
# Validate file encoding
file input_file.csv
chardet input_file.csvFor MySQL dumps from older versions, try changing the character set declaration in the dump file before importing:
-- In the dump file, change:
-- SET CHARACTER SET utf8;
-- To:
SET CHARACTER SET utf8mb4;Check your MySQL version:
SELECT VERSION();If running MySQL 5.5 or 5.6, upgrade to at least MySQL 5.7 or preferably MySQL 8.0. Older versions had bugs with LOAD DATA INFILE and escape characters followed by multi-byte sequences (fixed in MySQL 5.5.54+).
Check your MySQL version:
- MySQL 5.5.54+ has the LOAD DATA INFILE escape character fix
- MySQL 8.0+ defaults to utf8mb4 for all new databases
- MariaDB 10.3+ also includes the fixes
Advanced notes
Character Set Details: MySQL's utf8 is actually limited to 3-byte sequences (utf8mb3) and cannot store 4-byte UTF-8 characters like emoji (U+1F4A9), mathematical symbols (U+1D400-U+1D7FF), or rare CJK characters. Always use utf8mb4 for full UTF-8 support.
Performance Consideration: When converting large tables to utf8mb4, use CONVERT TO CHARACTER SET which rebuilds the entire table. For very large tables, consider creating a new table, migrating data in batches, and swapping table names to minimize downtime.
Platform-Specific Issues: SELinux on Linux systems may block file access during LOAD DATA INFILE. Windows paths in LOAD DATA INFILE require forward slashes: 'C:/path/to/file.csv' not 'C:\path\to\file.csv'.
Legacy Compatibility: If you must support legacy systems still using utf8mb3, verify the source data is truly utf8mb3-compatible before import rather than attempting to convert afterwards.
Frequently asked questions
- What does "1300" mean?
- MySQL ERROR 1300 (ER_INVALID_CHARACTER_STRING) is raised when MySQL detects an invalid character sequence for a specific character set. This happens most commonly when: 1. Character data contains multi-byte sequences that don't conform to UTF-8 or the specified character set encoding.
- How do I fix "1300"?
- MySQL ERROR 1300 occurs when the database encounters character data that doesn't conform to the expected character set encoding, typically during data import or string operations. This error is resolved by aligning character set configurations and ensuring your data uses the correct encoding.
- What causes "1300"?
- UTF-8 4-byte characters (emojis, certain CJK characters) in utf8mb3 columns that only support 3-byte characters Character set mismatch between the source data encoding and target table/column collation Mixed or corrupted encoding in source files where some characters are valid but others are malformed
- Is the "1300" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐MySQL Official Documentation
- ๐MySQL Docs - Error Reference (Error 1300)(Official Docs)
- ๐
- ๐