Solved

CSV into MySQL

Posted on 2014-01-06
6
472 Views
Last Modified: 2014-01-08
Hello,
At this point I am just gathering requirements and brainstorming about how to handle this project.  Is it something that should be done in code.  Is there an application out there that already does what I want that someone thinks I should use, etc...

So I would like to pick your brains.

We have a manual process were someone goes through 2 CSV files and manually manipulates data.  I want to put that data into a MySQL database and automate some of that manipulation for her.

The CSV files are uploaded to our server on a weekly basis by a 3rd party.
We have a Redhat Enterprise Linux 6 server with MySQL version 5.1.71, Webmin 1.660.

What would be the best process to create the MySQL database table and then create an automated process to import the data from the 2 CSV files (that have the same structure) into the database.  And then repeat the import once a week (roughly 6am on Mondays).

Does this make sense?

Is this best handled in code?
If so can you point me at some examples for best practices?

Or is there some sort of GUI that I can put on my server to schedule this for me?

Thanks in advance for your expertise.
0
Comment
Question by:Razzmataz73
  • 3
  • 3
6 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
Comment Utility
MySQL has LOAD DATA INFILE statement that could help.
REFMAN: http://dev.mysql.com/doc/refman/5.1/en/load-data.html

MySQL also has the mysqlimport program.
REFMAN: http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html

Kedar explains here:
http://www.experts-exchange.com/Database/MySQL/A_2250-Load-Delimited-Data-into-MySQL-Server.html

You can handle the scheduling (automation) of executing either import method via cron job, or other tools on the Linux server.  In addition, newer versions of MySQL have scheduled events.
REFMAN: http://dev.mysql.com/doc/refman/5.1/en/create-event.html
0
 

Author Comment

by:Razzmataz73
Comment Utility
Thank you Kevin.

If I have questions on this should I post it here?
Or after I make a decision on which way to go would it be better to start a new thread?
0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
What is the question?  If it helps you pick the solution, I say post it here as it may help others decide between the options as well.  If once you pick a solution, you have other questions a new thread is helpful as it allows us to focus on that issue independently as well as allows other Experts to chime in (as it will gain more attention as a new question).
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Razzmataz73
Comment Utility
Great.

I have my MySQL Dabases created on my server.  And our files are being uploaded on a weekly basis to the same server into a web folder location:
sailing-vacations.mobi/tuimarine

In particular it overwrites the files:
sailing-vacations.mobi/tuimarine/BROKERUSD.CSV
&
sailing-vacations.mobi/tuimarine/BROKERUSDSS.CSV

I am starting to go through your docs now, but if you could help me with getting the automation to work that would be perfect.

The MySQL Database is called
bareboats
and the table is called
rates

And the fields are:

rate_id
rate_create_date
rate_modified_date      
rate_basecode                       Matches up to column A of the CSV
rate_yacht                              Matches up to column B of the CSV
rate_crewed                           Matches up to column C of the CSV
rate_date                                Matches up to column D of the CSV
rate_charter_date                   Matches up to column E of the CSV
rate_dollars                            Matches up to column F of the CSV
rate_cents                              Matches up to column G of the CSV      
rate_currency                         Matches up to column H of the CSV
0
 

Author Comment

by:Razzmataz73
Comment Utility
OK,
I got this to work:

LOAD DATA INFILE '/var/www/sailing-vacations.mobi/tuimarine/BROKERUSDSS.CSV' INTO TABLE rates FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ;

LOAD DATA INFILE '/var/www/sailing-vacations.mobi/tuimarine/BROKERUSD.CSV' INTO TABLE rates FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ;

Now I just need to figure out how to automate that.
:)
0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
I would do that via scheduled task (cron tab) of server.  I am not a Linux person, so a new question may be helpful for that piece.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

762 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

9 Experts available now in Live!

Get 1:1 Help Now