Importing with phpMyAdmin

Importing with phpMyAdmin

am 09.02.2007 03:40:33 von Tgone

Hello,

I want to import a csv file into my table. However, I need to empty
the table before I do this. The problem is, I only see an option to
"replace" the data. Is there a way to empty a table AND simultaneously
import a csv? I know this is possible with the mysqlimport command
(with the --delete argument), but I'm not if it's possible in
phpMyAdmin.

I'm using phpMyAdmin 2.9.0.2 and MySQL 4.1.10

Thanks

Re: Importing with phpMyAdmin

am 09.02.2007 12:56:27 von Carl Pearson

Toine wrote:
> Hello,
>
> I want to import a csv file into my table. However, I need to empty
> the table before I do this. The problem is, I only see an option to
> "replace" the data. Is there a way to empty a table AND simultaneously
> import a csv? I know this is possible with the mysqlimport command
> (with the --delete argument), but I'm not if it's possible in
> phpMyAdmin.
>
> I'm using phpMyAdmin 2.9.0.2 and MySQL 4.1.10
>
> Thanks
>

This is more of a PHP question...

PMA's import function is for MySQL formatted data, not CSV.

Not sure about this "replace data" option to which you refer. It does
not exist in the import window.

To import CSV files you'd be using the SQL window, so you'd need two
lines in the query:

TRUNCATE

;
LOAD DATA INFILE INTO TABLE
FIELDS TERMINATED BY ',';

Replace
with the target table, and with the name of
your import file.

Note this may not work if you're on a shared host; you can't just point
PMA to a file on your local system & hope it will magically import up to
the server.

Options:
Re-format the CSV code into MySQL format, pre-pend a TRUNCATE statement
into the query, and use PMA's Import feature.

Write your own script to do the import, have it check IP to keep
malicious users from accessing it, and just bookmark it in your browser.