I'm trying to run some mysql scripts from the command line. One is autogenerated and it does not select the database before hand. Right now I have two scripts:
mysql -u <user> -p<password> < script1.sql
mysql -u <user> -p<password> < script2.sql
the last line of script1 is USE mydatabase;
but when I run script2 it says there is no database selected. Is there a way to specify what database to use for script2?
add the parameter -D like this
mysql -u<username> -p<password -D<database> < script.sql
mysql -u <user> -p<password> my_database_name < script2.sql
In your case happens because these are 2 separate processes and the queries from the first are not connected the ones from the second.
Another solution is to put USE database_name
as first line in script2.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With