What is a good practice to execute root operations on mysql databases in bash scripts?
For example, I want to create new database and grant privileges, I have to use:
mysql -u $ROOT -p"$ROOTPASS" -e "create database $DBNAME; GRANT ALL PRIVILEGES ON $DBNAME.* T $DBUSER@localhost IDENTIFIED BY $DBPASS";
But this requires storing mysql password for root user in the script itself.
Is there any more secure way?
Should I create separate user for this? How to set up the permissions?
The separate thing is how to test if the operation was successful, and if not, revert back the changes which were successfull (transaction?)