0

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?

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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