0

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

1 Answer 1

1

-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

Sign up to request clarification or add additional context in comments.

3 Comments

This appears to then show a sytax error - see edited post
i corrected my answer
Use ${cpuser}_mysql to avoid trying to expand a parameter named cpuser_mysql. The placement of the quotation marks in the original prevent this error.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.