Automate creating MySQL database and users for cPanel account

BraenDead

Member
Dec 8, 2008
5
0
51
Is there a way to automate creating databases and users in MySQL for a particular cPanel account? I can create the database and user in MySQL automatically, but then they do not show up in the list of databases for the user in cPanel. I beleive it has to do with updating the files in /var/cpanel/databases, although there may be other things that need to be set as well. Anyways, if there are any scripts or API's to handle this, that would help tremendously.

Thanks,

Bob
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
41
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
Hello Bob,

You can always try running /usr/local/cpanel/bin/dbmaptool to setup the mapping for the database to have it properly added to /var/cpanel/databases area, although I do suggest using the APIs instead if possible. You can get the options for /usr/local/cpanel/bin/dbmaptool by running the command without any parameters:

/usr/local/cpanel/bin/dbmaptool cpuser --type mysql|pg --dbusers 'user1, user2' --dbs 'db1, db2'

These flags are treated individually. This tool will not map a virtual user to a database.
/usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbs 'db1' --dbusers 'virt1'
/usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbs 'db1' && /usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbusers 'virt1'
The above two commands are analogous; result in cpuser 'user1' having privileges for 'db1' and having a virtual user named 'virt1.'
The API for MySQL is at the following location:

ApiMysql < ApiDocs/Api1 < TWiki

There are additional discussions on using the APIs for database mapping at these locations:

http://forums.cpanel.net/f42/case-4...ing-created-user-created-database-182011.html
More Details About DB Mapping - cPanel Integration
 

BraenDead

Member
Dec 8, 2008
5
0
51
I tried using the API and was able to access other tools, but the Mysql::adddb api does not seem to work for me. Anyways - I created a post in the developer forum for this. Thanks for the info.

Bob