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.
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.
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
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.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions