Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store .txt files MySQL database?

Can I store data files (e.g. txt files) to the MySql server? If I can, how to store them?

like image 439
Rida Shamasneh Avatar asked Mar 11 '11 21:03

Rida Shamasneh


2 Answers

You can use LOAD DATA INFILE to read the contents of a file and store it in a table in the database in a structured format.

This can be considerably faster than reading and parsing the file on the client and then using multiple INSERT statements.

Example:

LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
like image 177
Mark Byers Avatar answered Sep 29 '22 20:09

Mark Byers


Yes you can, but you would probably be better off storing them on the file system and storing a path to the file in the DB.

There are a few SO Posts that discuss this:

  • Storing Images in DB - Yea or Nay?
  • Storing a file in a database as opposed to the file system?
like image 36
Abe Miessler Avatar answered Sep 29 '22 20:09

Abe Miessler