MySqlBulkLoader class

MySqlBulkLoader lets you efficiently load a MySQL Server Table with data from a CSV or TSV file or Stream.

Example code:

using var connection = new MySqlConnection("...;AllowLoadLocalInfile=True");
await connection.OpenAsync();
var bulkLoader = new MySqlBulkLoader(connection)
	FileName = @"C:\Path\To\file.csv",
	TableName = "destination",
	CharacterSet = "UTF8",
	NumberOfLinesToSkip = 1,
	FieldTerminator = ",",
	FieldQuotationCharacter = '"',
	FieldQuotationOptional = true,
	Local = true,
var rowCount = await bulkLoader.LoadAsync();
public sealed class MySqlBulkLoader

Public Members

MySqlBulkLoader(…)Initializes a new instance of the MySqlBulkLoader class with the specified MySqlConnection.
CharacterSet { get; set; }(Optional) The character set of the source data. By default, the database’s character set is used.
Columns { get; }(Optional) A list of the column names in the destination table that should be filled with data from the input file.
ConflictOption { get; set; }A MySqlBulkLoaderConflictOption value that specifies how conflicts are resolved (default None).
Connection { get; set; }The MySqlConnection to use.
EscapeCharacter { get; set; }(Optional) The character used to escape instances of FieldQuotationCharacter within field values.
Expressions { get; }(Optional) A list of expressions used to set field values from the columns in the source data.
FieldQuotationCharacter { get; set; }(Optional) The character used to enclose fields in the source data.
FieldQuotationOptional { get; set; }Whether quoting fields is optional (default false).
FieldTerminator { get; set; }(Optional) The string fields are terminated with.
FileName { get; set; }The name of the local (if Local is true) or remote (otherwise) file to load. Either this or SourceStream must be set.
LinePrefix { get; set; }(Optional) A prefix in each line that should be skipped when loading.
LineTerminator { get; set; }(Optional) The string lines are terminated with.
Local { get; set; }Whether a local file is being used (default true).
NumberOfLinesToSkip { get; set; }The number of lines to skip at the beginning of the file (default 0).
Priority { get; set; }A MySqlBulkLoaderPriority giving the priority to load with (default None).
SourceStream { get; set; }A Stream containing the data to load. Either this or FileName must be set. The Local property must be true if this is set.
TableName { get; set; }The name of the table to load into. If this is a reserved word or contains spaces, it must be quoted.
Timeout { get; set; }The timeout (in milliseconds) to use.
Load()Loads all data in the source file or stream into the destination table.
LoadAsync()Asynchronously loads all data in the source file or stream into the destination table.
LoadAsync(…)Asynchronously loads all data in the source file or stream into the destination table.


Due to security features in MySQL Server, the connection string must have AllowLoadLocalInfile=true in order to use a local source.

See Also