Here is a little script I made to quickly and easily create users and databases for MySQL. I only use this for development, for actual deployed applications you would probably want to be more specific about the privileges given:
#!/bin/bash EXPECTED_ARGS=3 E_BADARGS=65 MYSQL=`which mysql` Q1="CREATE DATABASE IF NOT EXISTS $1;" Q2="GRANT ALL ON *.* TO '$2'@'localhost' IDENTIFIED BY '$3';" Q3="FLUSH PRIVILEGES;" SQL="${Q1}${Q2}${Q3}" if [ $# -ne $EXPECTED_ARGS ] then echo "Usage: $0 dbname dbuser dbpass" exit $E_BADARGS fi $MYSQL -uroot -p -e "$SQL"
To use it, just run:
./createdb testdb testuser secretpassThat command would create a database named testdb, and user testuser with the password of secretpass.

July 27th, 2009 at 8:29 am
Thank you for this script – it saved me some time!
August 14th, 2009 at 1:33 pm
props, thanks for the script
June 16th, 2010 at 12:26 pm
Very useful script. Thanks
July 25th, 2010 at 2:02 pm
thanks