Tue 12 Apr 2011
Some MySQL tips:
Running a shell script from within MySQL:
mysql> \! /user/myscript
Running a script of MySQL commands from within MySQL:
mysql> source /user/myscript;
Running MySQL from within a shell script and running commands to create a database and user:
mysql -u$ROOTUSER -p$ROOTPASSWD << CREATE_DB
CREATE DATABASE $DBNAME;
GRANT ALL PRIVILEGES ON $DBNAME.* TO "$DBUSER"@"localhost" IDENTIFIED BY "$DBPASSWD";
FLUSH PRIVILEGES;
CREATE_DB
Running MySQL from shell script or command line and passing a single command
mysql -u root -p -e STATUS | grep -i uptime