Cannot execute "LOAD DATA LOCAL INFILE" Mysql query in Rails after a connection reconnection

Posted by Ngan on Stack Overflow See other posts from Stack Overflow or by Ngan
Published on 2011-01-10T22:41:09Z Indexed on 2011/01/10 22:53 UTC
Read the original article Hit count: 263

Filed under:
|
|

On Rails 2.3.8 (but I think Rails 3 might have this issue as well, not sure):

I get an error when trying to execute a LOAD DATA LOCAL INFILE query after reconnecting to a database. I have a process that parses a file that can potentially take a bit of time. During the parsing, Mysql closes the connection due to timeout. This is fine, I do a ActiveRecord::Base.verify_active_connections! and I get the connection back (I do this in several places through my app). However, running a LOAD DATA LOCAL INFILE statement, I get this error:

Mysql::Error: The used command is not allowed with this MySQL version

It's not a permission issue, I know that for sure. Check out my test in console:

> ActiveRecord::Base.connection.execute("LOAD DATA LOCAL INFILE '/tmp/test.infile' INTO TABLE users")
[Sat Jan 08 00:09:29 2011] (9990)   SQL (1.7ms)   LOAD DATA LOCAL INFILE '/tmp/test.infile' INTO TABLE users
 => nil

> ActiveRecord::Base.connection.disconnect!
 => #<Mysql:0x104c6f890>

> ActiveRecord::Base.verify_active_connections!
[Sat Jan 08 00:09:58 2011] (9990)   SQL (0.2ms)   SET SQL_AUTO_IS_NULL=0
 => {...connection stuff...} 

> ActiveRecord::Base.connection.execute("LOAD DATA LOCAL INFILE '/tmp/test.infile' INTO TABLE users")
[Sat Jan 08 00:10:00 2011] (9990)   SQL (0.0ms)   Mysql::Error: The used command is not allowed with this MySQL version: LOAD DATA LOCAL INFILE '/tmp/test.infile' INTO TABLE users
ActiveRecord::StatementInvalid: Mysql::Error: The used command is not allowed with this MySQL version: LOAD DATA LOCAL INFILE '/tmp/test.infile' INTO TABLE users
    from ~/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `log'
    from ~/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
    from (irb):6

I am able to do other queries like SELECT and whatnot, and I will get the correct result. It's just this one that giving me the error. I even tested this with a fresh rails app. You'll notice that I am able to do the exact same query before the disconnect.

Thanks for the help!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about ruby-on-rails