Note that there are some explanatory texts on larger screens.

plurals
  1. POLOAD DATA LOCAL INFILE causes Malformed packet error with mysql2 gem
    primarykey
    data
    text
    <p>I'm trying to issue a LOAD DATA LOCAL INFILE query to load some CSV data into a table using the mysql2 gem (0.3.11) under rails 3.1.1:</p> <pre><code>class Foo &lt; ActiveRecord::Base def self.load_csv query = "LOAD DATA LOCAL INFILE 'test/foo.csv' REPLACE INTO TABLE foos LINES TERMINATED BY '\n' (title)" ActiveRecord::Base.connection.execute(query) end end </code></pre> <p>(This is a sample app to reproduce the error for <a href="https://github.com/brianmario/mysql2/issues/43" rel="nofollow noreferrer">this github issue</a>). This keeps failing <strong>on OS X (Lion)</strong> with the following error:</p> <pre><code>Mysql2::Error: Malformed packet: LOAD DATA LOCAL INFILE 'test/foo.csv' REPLACE INTO TABLE foos LINES TERMINATED BY ' ' (title) </code></pre> <p>Local infile is enabled on the server: </p> <pre><code>mysql&gt; show variables where variable_name like '%local%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | local_infile | ON | +---------------+-------+ </code></pre> <p>and on the client via this directive in application.rb:</p> <pre><code>Mysql2::Client.default_query_options[:connect_flags] |= Mysql2::Client::LOCAL_FILES </code></pre> <p>The same LOAD statement works fine from the MySQL client. Changing the DB connection method from socket to TCP/IP makes no difference. MySql is installed via homebrew and the version is</p> <pre><code>mysql Ver 14.14 Distrib 5.5.15, for osx10.7 (i386) using readline 5.1 </code></pre> <p>I do NOT get this error running the same code under Linux. It also works if I omit the LOCAL modifier, but that is not an option as the file is in fact local in production and the database server remote. It has nothing to do with file permissions as in <a href="https://stackoverflow.com/questions/2420140/malformed-packet-error-during-mysql-load-data-local-infile">this</a> question.</p> <p>This is driving me nuts, any insights are greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload