Home > database >  Insert from SQL shell script
Insert from SQL shell script

Time:02-02

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

CodePudding user response:

-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

  • Related