I was building a .NET C# application with a MySQL database, and I too kept running into the error message:
"Fatal error encountered during command execution."
When calling the "LOAD DATA INFILE" MySQL command from my .NET application. It was very hard to figure out the solution, so I wanted to respond here with the solution that worked for me. Eventually, after several days of reading everything I could find about the problem (including this post), I was able to fix it...and the solution was not intuitive by any means, and it ended up being two different issues!
The first fix I found was that, when you're using variables in your INFILE, you need to add the following statement to your connection string (believe it or not):
"Allow User Variables=True;"
So, that means your complete connection string should look something like this:
"server=127.0.0.1;uid=user;pwd=password;database=mysql_db_name;Allow User Variables=True"
This surprised me, but seemed to work!! I found that solution here:
MySQL fatal error encountered during command execution - looping through all csv files in folder for load data local infile
However, after I modified the connection string, although most input files started working for me, I was STILL getting this error message intermittently. I would get the error message "Fatal error encountered during command execution" for some input files and not others?? After reading more and playing around with things, it seemed to be a problem of the connection timing out (or something weird like that), even though the error message did NOT say anything about a connection timeout. I was able to stop the error message from popping up and correctly import data files into MySQL by increasing the "CommandTimeout" property on the database "MySqlCommand" object in C#, like this:
mysqlCommand.CommandTimeout = 600;
So, the full code looked something like this:
string strConnect = "server=127.0.0.1;uid=user;pwd=password;database=mysql_db_name;Allow User Variables=True";
Using (MySqlConnection mysqlConnection = new MySqlConnection(strConnect))
{
Using (MySqlCommand mysqlCommand = new MySqlCommand())
{
mysqlCommand.CommandTimeout = 600;
mysqlCommand.Connection = mysqlConnection;
mysqlCommand.CommandType = CommandType.Text;
mysqlCommand.CommandText = "LOAD DATA INFILE (...your specific command here)";
try
{
mysqlConnection.Open();
mysqlCommand.ExecuteNonQuery();
mysqlConnection.Close();
}
catch(Exception ex)
{
// handle errors
}
}
}
And I found that particular solution after reading this post:
Sourcing 'Fatal Error' resulting from MySQL ExecuteNonQuery?
Anyway, I think that was everything I needed to do to solve my problem. Hopefully this information is helpful for you too. Good luck and happy coding!