Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a CSV file that has 2 columns

Name 
Email

I have a table in my database that has the same columns + some extra columns.

Now I would like to update my db table using that csv file. I mean like this

UPDATE `mytable` SET `email` = 'csvemail' WHERE `name` = 'csvname'

Can someone help me to do that from my ubuntu terminal?

share|improve this question
add comment

1 Answer 1

MySQL has built-in support for importing data from CSV files, just use the command-line client :

mysql -u <user> -p

(replace <user> with your MySQL username and enter the password when asked to)

Then, tell MySQL to use your database :

USE <database>;

(replace <database> with the database name)

And finally, use this to import everything from your CSV file :

LOAD DATA INFILE '<path>' INTO TABLE <table>;

(replace <path> with the full path to the CSV file such as /home/user/file.csv and <table> with the table name).

Look at this question and this one that may be related to your question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.