title: Error loading MySQL/MariaDB Inline Data With Unescaped Double Quotes In Fields
body: <p>I am having essentially the same problem as <a href="https://stackoverflow.com/questions/23497172/error-with-mysql-load-data-infile-field-with-double-quotes">described here</a> but the issue was left unresolved in that question.</p>
  <p>I am trying to import a series of data files totaling about 100 million records into a MariaDB database. I've run into issues with some lines in the import file that look like:</p>
  <pre><code>&quot;GAYATRI INC DBA &quot;WHIPIN&quot;&quot;,&quot;1950&quot;,&quot;S I&quot;,&quot;&quot;,&quot;AUSTIN&quot;,&quot;TX&quot;,&quot;78704&quot;,&quot;5124425337&quot;,&quot;B&quot;,&quot;93&quot;
  </code></pre>
  <p>which I was trying to load with a statement like:</p>
  <pre><code>LOAD DATA INFILE 'testline.txt'
  INTO TABLE data
  FIELDS TERMINATED BY ',' ENCLOSED BY '&quot;'
  LINES TERMINATED BY '\r\n'
  (@name,@housenum,@street,@aptnum,@city,@state,@zip,@phone,@business,@year)
  SET name=@name, housenum=@housenum, street=@street, aptnum=@aptnum, city=@city, state=@state, zip=@zip, phone=@phone, business=@business, year=@year;
  </code></pre>
  <p>but am receiving errors because the first field contains unescaped double quotes in the text of the field. That seems to be OK in and of itself as the database seems <a href="https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-field-line-handling" rel="nofollow noreferrer">smart enough to handle that</a> in most situations. However, because the field ends with a double quote in the text plus a double quote to close the field it assumes the first double quote is escaping the second double quote following <a href="https://www.ietf.org/rfc/rfc4180.txt" rel="nofollow noreferrer">RFC4180</a> and thus is not terminating the field even though the next character is a comma.</p>
  <p>The source files can't be created any differently as they are exports from old software which I do not control. Obviously searching through 100 million records and changing entries like this by hand is not feasible. I'm unsure of whether any fields might contain commas though it's probably safe to assume they do in this quantity of records so programmatically forcing fields to break at commas is probably out too.</p>
  <p>Any ideas on how to get them to import correctly?</p>