Solved

Importing a text file using a MySQL stored procedure

Posted on 2008-10-02
2
1,259 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now