creating MySQL database from PHP script?

OK, thanks for that.

It seems then, that my user is restricted to doing it only from within DA, since I can't even do it from PhpMyAdmin. There is no way for option in the permissions screen for me to give a db user, access to create db's :(

It's so that the website can create databases on the fly from a script each time a customer signs up for our service. I guess I'll just have to stick to creating tables instead.

Thanks and Regards, peter
 
It's so that the website can create databases on the fly from a script each time a customer signs up for our service. I guess I'll just have to stick to creating tables instead.

Sorry I didn't see this earlier.

I use the following code in /usr/local/directadmin/scripts/custom/user_create_post.sh

Code:
# read mysql access stuff
DA_MYSQL=/usr/local/directadmin/conf/mysql.conf
DA_USER=`cat $DA_MYSQL | grep user= | cut -d= -f2`
DA_PASS=`cat $DA_MYSQL | grep passwd= | cut -d= -f2`

NEW_DB="${username}_db1"
NEW_USER="${username}@localhost"

# create database
mysql -u $DA_USER -p$DA_PASS --execute="CREATE DATABASE $NEW_DB"

#create user
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

#create default user
NEW_USER="${username}_usr@localhost"
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

It creates a database automatically when creating a new account on the server. You may want to change a few aspects for your particular needs.

Mike
 
Back
Top