Skip to main content

Create Database, User and set permissions via SSH

Comments

3 comments

  • cPanelMichael
    Hello :) You must manually create the databases and database users through MySQL itself. You can then determine if it's assigned to an account using "/usr/local/cpanel/bin/dbmaptool". Here are the options for this utility: # /usr/local/cpanel/bin/dbmaptool /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.'
    Thank you.
    0
  • vestigium
    Searching a bit more I ended up finding the cPanel API. I saw that the v1 API functions are available to create both user and database: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api1/ApiMysql]Mysql Module Documentation Could do everything I needed by making an API request via curl the following urls: // Create database https://mydomain.com:2083/json-api/cpanel?user=CPANELUSER&cpanel_jsonapi_module=Mysql&cpanel_jsonapi_func=adddb&cpanel_jsonapi_apiversion=1&arg-0=DATABASE // Create user https://mydomain.com:2083/json-api/cpanel?user=CPANELUSER&cpanel_jsonapi_module=Mysql&cpanel_jsonapi_func=adduser&cpanel_jsonapi_apiversion=1&arg-0=DATABASEUSER&arg-1=DATABASEUSERPASSWORD // Grant a user permission (all) https://mydomain.com:2083/json-api/cpanel?user=CPANELUSER&cpanel_jsonapi_module=Mysql&cpanel_jsonapi_func=adduserdb&cpanel_jsonapi_apiversion=1&arg-0=DATABASE&arg-1=DATABASEUSER&arg-2=all
    0
  • cPanelMichael
    I am happy to see you were able to find a suitable solution. Thank you for updating us with the outcome.
    0

Please sign in to leave a comment.