I'm using this command syntax :
mysqldump -u<username> -p<password> --no-create-db --databases mydatabase > /var/backups_DB/MyDatabase-$(date +"%d-%m-%Y-%H:%M:%S").sql
But I could not find how to prevent the line "use mydatabase" to be inserted in the generated file. Which option should I use?
Exactly. Remove --databases
...
https://www.computerhope.com/unix/mysqldum.htm
--databases
-B
Dump several databases. Normally, mysqldump treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names. CREATE DATABASE and USE statements are included in the output before each new database.
As @wchiquito said in comments, in order to avoid to have the "USE databasename
" statement in dump file you must remove the --databases
option.
If you don't have the choice, you can remove it afterwards using a Unix sed command :
cat sourcefile.sql | sed '/USE `databasename`;/d' > destfile.sql
Thomas
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