views:

479

answers:

4

Is it possible to import csv data into mysql and automatically create the column names, as in can I create just the table, or must I create the table names as well?

Is it possible to check for duplicate entries upon importing? I have an identifier field, but dont know how to make it so it will not be imported twice.

How would you import a jpeg file on a website into a field? Assume the website has been stored locally, and has the same filename as an identifer with ".jpeg" added on to the end.

A: 

Sure, but you'll probably have to write a few lines of code yourself, it can be done with very little code. Checking for duplicates is quite easy then, you can do that before inserting in your little script.

You could store the file as a combination of two fields, one Varchar for the name and a blob for the file contents.

tante
A: 
  1. No
  2. You could add a unique constraint - it really depends what you want to do if a duplicate is found
  3. Not using mysql - use a scripting language to pull the image data from the URL then insert that
Greg
+2  A: 

As tante said you'll have to handle the table creation yourself, but as far as importing csv is concerned you should have a look at LOAD DATA INFILE

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[CHARACTER SET charset_name]
[{FIELDS | COLUMNS}
    [TERMINATED BY 'string']
    [[OPTIONALLY] ENCLOSED BY 'char']
    [ESCAPED BY 'char']
]
[LINES
    [STARTING BY 'string']
    [TERMINATED BY 'string']
]
[IGNORE number LINES]
[(col_name_or_user_var,...)]
[SET col_name = expr,...]

Duplicate entries won't be a problem if you have set primary keys on your table.

The jpeg question seems like a completely different issue (unless the data is in your csv)

Ken
+1  A: 

Looks like the answers you got covers at least the first two items. For the Jpeg question, take a look at Storing a file in a database as opposed to the file system?.

PhiLho