在測試時發現有的表用MySqlBulkLoader一直加不上數據,通過檢查,原來是由於表中的列名跟MYSQL的一個關鍵詞對上了,因此在執行時把列名當作關鍵詞進行處理了。測試
LOAD DATA LOCAL INFILE ':STREAM:364a6d1293584ac4afdaf58a30adc9d2' INTO TABLE test_table CHARACTER SET utf8mb4 FIELDS TERMINATED BY '|' LINES TERMINATED BY ' ' (id,name,type,Range)
若是不指定列名則是:spa
LOAD DATA LOCAL INFILE ':STREAM:364a6d1293584ac4afdaf58a30adc9d2' INTO TABLE test_table CHARACTER SET utf8mb4 FIELDS TERMINATED BY '|' LINES TERMINATED BY ' '
這樣也是能夠正常插入的。code
可是若是想指定列名的話,就須要對列名進行處理:blog
MySqlBulkLoader bulk = new MySqlBulkLoader(connection) { FieldTerminator = ",", CharacterSet = "utf8mb4", //FieldQuotationCharacter = '"', //EscapeCharacter = '"', LineTerminator = Environment.NewLine,//"\r\n", FileName = @"D:\TestData\test2.csv", NumberOfLinesToSkip = 0, TableName = "test_table", }; for (int i = 0; i < columns.Count(); i++) { var oneColumns = columns[i]; columns[i] = $"`{oneColumns}`"; } bulk.Columns.AddRange(columns); return bulk.Load();
主要是將列名用"`"號包起來就能夠了。ip