Solved

Importing a text file using a MySQL stored procedure

Posted on 2008-10-02
2
1,268 Views
Last Modified: 2012-05-05
Hi guys,
Id like to find out from you kind gurus if there is a way to create a stored procedure, that accepts one parameter (that being the name of a text file), to be able to import that text file into a mysql table?

Any help greatly appreciated.
0
Comment
Question by:Simon336697
  • 2
2 Comments
 
LVL 11

Accepted Solution

by:
Goodangel Matope earned 500 total points
ID: 22630598
Absolutely! You can use the LOAD DATA INFILE statement in your query. You can get a detailed explanation in your MYSql Reference, but below is an idea of what you can do. All you do is create a procedure that accepts the file name
LOAD DATA INFILE filename
  INTO TABLE t1
  FIELDS TERMINATED BY ','
  (column1, column2)

Open in new window

0
 
LVL 11

Expert Comment

by:Goodangel Matope
ID: 22630626
Oops, sorry, LOAD DATA is not allowed in stored procedures. so you will have to run a query with the LOAD DATA statement from your PHP / ASP / application directly! :-(
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question