database creation using API and/or scripts

mike_p

Verified User
Joined
Aug 26, 2004
Messages
101
Hi

1. The story up until now.

I've been having trouble creating a database using the API.

My discussion has been in the sticky thread regarding the API and classes - but I guess it doesn't really belong there.

I have a feeling there must be some error in my DA setup - which may relate to some manual recompiles I did for some things when I first got my DA equipped box (before I knew the DA way of upgrading PHP etc).

Can anyone suggest any way of analysing/debugging my problem? (More details in http://www.directadmin.com/forum/showthread.php?s=&postid=30197#post30197 ).
====================
2. Moving on.

What I am trying to achieve is the automatic creation of a default mySQL database on creation of a new user account.

The best place to achieve this would be in the user_create_post.sh script.

What syntax can I use there to create a database?
Should I use the API, or should I use mysql directly?
If I use mysql, as which user should I log in and with what password? Are there any other DirectAdmin files that I would need to update?

Thanks for any help
 
I know this is an EXTREMELY old post, but I need to do the same thing: create a database automatically when I create a user. Did you ever figure out how to do this?
 
Yes, I did.

Apologies for not posting the solution when I first wrote it|!

Within my user_create_post script I have
Code:
##
# create default database
##

# 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}'"
 
Last edited:
Back
Top