加载数据输入文件:无效的 ut8mb4 字符串

2022-01-15 00:00:00 mariadb mysql load-data-infile

我正在使用 LOAD DATA INFILE 导入一些大表 (iTunes EPF).

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: 'אל נא תלך'"

表是这样创建的:

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)

推荐答案

正如 Rick James 建议的那样,在 LOAD 语句之前运行 SET NAMES utf8mb4; 就可以了.

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

相关文章