How to Import CSV data to a MySQL table in a database from command line?

September 14, 2011 at 7:33 pm Leave a comment

First log into MySQL from command line and create the table “table_user” under the database “db_user”

mysql> use db_user;

mysql> desc table_user;
+——-+————–+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——-+————–+——+—–+———+—————-+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| age | varchar(20) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
+——-+————–+——+—–+———+—————-+
4 rows in set (0.00 sec)

mysql> load data local infile ‘/userinfo.csv’
-> into table table_user
-> fields terminated by ‘,’
-> lines terminated by ‘\n’
-> (name, age, email);

Note: “id” field is skipped from the list for it to be auto incremented.

Check more information at kurinchilamp.kurinchilion.com

Advertisement

Entry filed under: Apache, MySQL. Tags: , , .

JQuery: Showing a progress image while processing background task

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

September 2011
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
2627282930  

Blog Stats

  • 19,330 hits

Follow

Get every new post delivered to your Inbox.