PDA

View Full Version : HELP importing .CSV into mysql database!!


ksaphan
9-26-05, 08:33 AM
Hi,

I've got an .CSV file in the following format:

"number1","number2","text","text","text"

and so on, nearly 50000 lines.

I need to create table and insert all info from this file into table. How to do it?
Please help me.

Thanks, ksaphan

mitchind
9-26-05, 11:04 AM
Use phpmyadmin
click on the table
click on the SQL tab
click on the link at bottom "Insert data from a text file into the table "

Locate your text file
Specify your file setup

If the file's really big, you'll have to split it into smaller chuks of data and do each one separately

ksaphan
9-26-05, 02:35 PM
and how can I do it via php script?

ksaphan
9-26-05, 02:35 PM
if I already uploaded this file on the web

ksaphan
9-26-05, 02:57 PM
I need to do something like:

$query = 'load data infile \'/www/b/bemyartcom/htdocs/db/somefile.csv\' into table tablename fields terminated by \',\' enclosed by \'"\' lines terminated by \'\r\n\'';

mysql_query($query);

but it does nothing.
Help!!!

mitchind
9-26-05, 04:14 PM
Seems to me that if this is a one-time shot, it would be just as easy to download it locally and run it thu phpmyadmin

But ... If you want to do it thru php you can use the shell command "mysqlimport"

Would be easier to test the syntax if you had already installed phpmyshell, but you can play with the syntax, defining the parameters and such if you want.

Manual: http://dev.mysql.com/doc/mysql/en/mysqlimport.html