title: Insert Data into Single MySQL Table Concurrently by Multi-thread in C++
body: <p>I am doing an experiment that concurrently insert data into a MySQL table by multi-thread.</p>
  <p>Here is partial code in C++.</p>
  <pre><code>    bool query_thread(const char* cmd, MYSQL* con) {
        if( !query( cmd, con ) ) {
          return 0;
        }
        return 1;
      }
      int main() {
            ........
        if(mysql_query(m_con, &quot;CREATE TABLE tb1 (model INT(32), handle INT(32))&quot;) != 0) {
          return 0;
        }
          
        thread thread1(query_thread, &quot;INSERT INTO tb1 VALUES (1,1)&quot;, m_con);
        thread thread2(query_thread, &quot;INSERT INTO tb1 VALUES (2,2)&quot;, m_con);
        thread thread3(query_thread, &quot;INSERT INTO tb1 VALUES (3,3)&quot;, m_con);
        thread1.join();
        thread2.join();
        thread3.join();
      }
  </code></pre>
  <p>But the MySQL error message is issued.</p>
  <blockquote>
  <p>error cmd: INSERT INTO tb1 VALUES (1,1)</p>
  <p>Lost connection to MySQL server during query</p>
  <p>Segmentation fault</p>
  </blockquote>
  <p>My questions are as following.</p>
  <ol>
  <li>Is it because the MySQL cannot accept concurrently insertion? Or bad use of multi-thread.</li>
  <li>By multi-thread insertion as above, does it help to speed up the program? I understand the best way are multiple insert per query and LOAD DATA INFILE. But I just want to know if this way can help.</li>
  </ol>