# Import txt file to mysql with ruby & load data local?

**URL:** <https://www.ruby-forum.com/t/import-txt-file-to-mysql-with-ruby-load-data-local/66340>\
**Category:** Ruby\
**Created:** [August 24, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/import-txt-file-to-mysql-with-ruby-load-data-local/66340 "2006-08-24T20:26:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@mtubbs](https://www.ruby-forum.com/u/mtubbs)\
**Post date:** [August 24, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/import-txt-file-to-mysql-with-ruby-load-data-local/66340/1 "2006-08-24T20:26:36Z")

</div>

I’m trying to run this sql from within a ruby program

LOAD DATA LOCAL INFILE ‘C:\test.txt’ INTO TABLE `links` FIELDS  
TERMINATED BY ‘;’ ENCLOSED BY ‘"’ ESCAPED BY ‘\’ LINES TERMINATED BY  
‘\r\n’  
will this even work with ruby? what should syntax be?

require “rubygems”  
require “mysql”

begin

```
    dbName = "testdb"
    m = Mysql.new("localhost", "root", "")
    m.select_db(dbName)
    result = m.query(???)
    puts "done"

```

end

??

---

<div class="post-metadata">

**Author:** ![mtubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@mtubbs](https://www.ruby-forum.com/u/mtubbs)\
**Post date:** [August 24, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/import-txt-file-to-mysql-with-ruby-load-data-local/66340/2 "2006-08-24T22:37:14Z")

</div>

Mike Turco wrote:

> I’m trying to run this sql from within a ruby program
> 
> LOAD DATA LOCAL INFILE ‘C:\test.txt’ INTO TABLE `links` FIELDS  
> TERMINATED BY ‘;’ ENCLOSED BY ‘"’ ESCAPED BY ‘\’ LINES TERMINATED BY  
> ‘\r\n’  
> will this even work with ruby?

Yes, if it will work with MySQL directly, it should work here as well.

> what should syntax be?

It should be valid MySQL syntax. Why not do some experiments?

If you have valid MySQL strings, strings that created what you expected  
from  
past experience, those strings will work here as well.

You can always test your syntax in advance using the command-line mysql  
interface:

$ echo “string of MySQL commands;” | mysql -u $USER -p (password)

Basically, this question is more about MySQL than it is about Ruby.  
Chances  
are your valid strings will work with Ruby’s MySQL interface.

Maybe some experimentation is in order.
