Change MySQL root password with bash script
If you're asking how to run more than one statement with a single mysql
command, you can either simply separate them by semicolons:
$ mysql -e 'select 1; select 2'
+---+
| 1 |
+---+
| 1 |
+---+
+---+
| 2 |
+---+
| 2 |
+---+
or you can create a file containing the SQL statements and run that:
$ mysql < change_password.sql
Use mysqladmin instead of running a query in mysql.
mysqladmin -u root -p'$oldrootpass' password '$newrootpass'
should work but you might need to mess with the quotes a little.