LOAD DATA INFILE: Invalid ut8mb4 character string
Asked Answered
U

1

4

I'm using LOAD DATA INFILE to import some big tables (iTunes EPF).

However, the import fails with this error:

string(52) "Invalid utf8mb4 character string: 'אל נא תלך'"

The table is created like this:

CREATE TABLE `song-tmp` (
  `song_id` int(11) NOT NULL DEFAULT '0',
  `name` varchar(1000) DEFAULT NULL,
  `title_version` varchar(1000) DEFAULT NULL,
  `artist_display_name` varchar(1000) DEFAULT NULL,
  PRIMARY KEY (`song_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

This is the import query I'm using:

LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE `song-tmp`
  CHARACTER SET utf8mb4
  FIELDS TERMINATED BY X'01' 
  LINES TERMINATED BY X'020a'
  (@export_date, song_id, name, title_version, @search_terms, @parental_advisory_id, artist_display_name, @collection_display_name, @view_url, @original_release_date, @itunes_release_date, @track_length, @copyright, @p_line, @preview_url, @preview_length)
Unending answered 29/1, 2017 at 14:35 Comment(2)
Looks good. Try running SET NAMES utf8mb4; before the LOAD statement.Exhortative
@RickJames thank you! solved.Unending
U
5

As Rick James suggested, running SET NAMES utf8mb4; before the LOAD statement did the trick.

Unending answered 3/2, 2017 at 12:31 Comment(1)
Thank you so much. This took me probably an hour to find. I'm glad your answer was so clear.Sauna

© 2022 - 2024 — McMap. All rights reserved.