Requirements:

 

  • Root access to the WHM Server.

 

Procedure

 

Let’s say the cPanel account username is ‘rootadminz’, and you want to create a database named ‘rootadminz_website’ under this cPanel account.

 

1. Log in to the root of your Server

 

2. Run the following command to create the database named ‘rootadminz_website’ under ‘rootadminz’ cPanel account.

uapi --user=rootadminz Mysql create_database name=rootadminz_website

 

Note:–

Database name should contain cPanel Username followed by an underscore or else uapi command won’t accept and give you an error for same.

 

3. Run the following command to create the MySQL user named ‘rootadminz_dbuser’.

uapi --user=rootadminz Mysql create_user name=rootadminz_dbuser password=helloworld

 

Simply replace ‘rootadminz_dbuser’ and ‘helloworld’ in the above command with the database username and password of your preference.

 

Note:–

Database user should contain cPanel Username followed by an underscore or else uapi command won’t accept and give you an error for same.

 

Finally, add the user to the database with this command.

uapi --user=rootadminz Mysql set_privileges_on_database user=rootadminz_dbuser database=rootadminz_website privileges=ALL%20PRIVILEGES

 

Replace “ALL%20PRIVILEGES” with the specific privileges that match your preference, as documented at:

https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Mysql%3A%3Aset_privileges_on_database

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)