lukederbyshire
lukederbyshire

Reputation: 27

Insert from SQL shell script

Good evening

I am trying to insert data from one table to another in my script and it comes up with database not found - have I done something wrong?

mysql -e INSERT INTO mysql.db SELECT * from "$cpuser"_mysql.db;

CPUser is a variable manually assigned earlier in the script.

From the CLI I can select * from both

Output from comment;

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''domain7mysql4'_mysql.db' at line 1
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''domain7mysql4'_mysql.user' at line 1

Upvotes: 0

Views: 68

Answers (1)

nbk
nbk

Reputation: 49373

-se expects a string, so you need to provide one

mysql -e "INSERT INTO mysql.db SELECT * from `${cpuser}_mysql`.db;" 

or

mysql -e "INSERT INTO mysql.db SELECT * from ${cpuser}_mysql.db;" 

if there are no reserved text

Upvotes: 1

Related Questions