title: Most efficient way to insert Rows into MySQL Database
body: <p>I've read a lot of questions about that but i couldn't find one that is fast enough. I think there are better ways to insert a lot of rows into a MySQL Database</p>
  
  <p>I use the following code to insert 100k into my MySQL-Database:</p>
  
  <pre><code>public static void CSVToMySQL()
  {
      string ConnectionString = "server=192.168.1xxx";
      string Command = "INSERT INTO User (FirstName, LastName ) VALUES (@FirstName, @LastName);";
      using (MySqlConnection mConnection = new MySqlConnection(ConnectionString))
      {
          mConnection.Open();
  
          for(int i =0;i&lt; 100000;i++) //inserting 100k items
          using (MySqlCommand myCmd = new MySqlCommand(Command, mConnection))
          {
              myCmd.CommandType = CommandType.Text;
              myCmd.Parameters.AddWithValue("@FirstName", "test");
              myCmd.Parameters.AddWithValue("@LastName", "test");
              myCmd.ExecuteNonQuery();
          }
      }
  }
  </code></pre>
  
  <p>This takes for 100k rows about 40 seconds. How can i make this faster or a little more efficient? </p>
  
  <p>Might be faster to insert multiple rows via a DataTable/DataAdapter or at once:</p>
  
  <pre><code>INSERT INTO User (Fn, Ln) VALUES (@Fn1, @Ln1), (@Fn2, @Ln2)...
  </code></pre>
  
  <p>Due to security issues i can't load the data into a file and MySQLBulkLoad it.</p>