I know I can do some thing like this in script:
mysql -u root -pPassword mydb -e "select * from foo"
In my script I have a sequence of commands which some of them are periodically related to MySQL and others are independent (so I cannot use Here Documents). It seems it is necessary to add -u root -pPassword part in all commands to avoid getting this error:
Access denied for user 'user'@'host' (using password: NO)
But is annoying. Is there a way to avoid adding -u root -pPassword part to all commands?
mysql?rmysqlthat connects asrootand looks something like:mysql -u root -pXXXXX $*so you can get in quickly in case of emergency. Lock that script down mode 0700 to avoid others seeing the password.