MySQLadmin drop database – bash script

bashMySQL

I have a bash script which downloads a sql.gz file, extracts it and then import it, however before importing, I drop the existing DB, then import the new DB onto the server.

All is well and the script does what it is supposed to, only one thing :
I have this statement in my bash script :
mysqladmin -uroot -ppassword drop dbname
which then waits for user input to press y or n to continue.

Is there a way I can input Y so it always says yes and automatically completes the script.
I am new (v.new) to bash scripts.

Thanks
Kind Regards

Best Answer

echo Y | mysqladmin ...

Or

mysql -u root -e 'your sql commands' dbname

Please note that from security point of view you should not provide user credentials on command line. Instead you should create a preference file ~/.myrc or so and fill the necessary information there. That way your user info won't be revealed through process list.