JanneFiH
JanneFiH

Reputation: 1

How do I chose which db to use?

I want to insert data with a csv-file. I want to do this by having this row in a bash script:

mysql -uusername -ppassword "LOAD DATA LOCAL INFILE 'CSVname.csv'  INTO TABLE table_name  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"

But I'm not sure where in this string I can select which DB to use. Only which table. I get it to work if I enter it manually with "use dbname" and then LOAD DATA etc..

Can anyone please help?

Thanks in advance!

Upvotes: 0

Views: 88

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94682

A simple look at the manual would have helped you here, it did me.

All you need to do is add the database name in front of the table name like this:

mysql -uxxx -p yyy "LOAD DATA LOCAL INFILE 'CSVname.csv'  INTO TABLE 
databasename.table_name  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"

Upvotes: 1

Related Questions