Today we will learn how to Create a database and user using the command line on the WHM server. Don’t like the web interface and looking for commands to create MySQL databases and users using the command line on WHM Server? Want to automate database and user creation using scripts on your WHM server? This guide will show how we can use the terminal to create a MySQL database and user on cPanel/WHM server. Commands are straightforward and neat.
Let’s move on with the guide
Requirements for Create database and user on WHM server
Root access to the WHM server
Procedure
Let’s say the username of the cPanel account is ‘basezap’, and you want to create a database named ‘basezap_website’ under this cPanel account.
-Log in to your server root.
-Run the following command to create a database named ‘basezap_website’ under ‘basezap’ cPanel account.
uapi --user=basezap Mysql create_database name=basezap_website
Note – The database name should contain the cPanel username followed by an underscore or the uapi will not accept the command and will give you an error for the same.
-Run the following command to create a MySQL user named ‘basezap_dbuser’.
uapi --user=basezap Mysql create_user name=basezap_dbuser password=helloworld
Just replace ‘basezap_dbuser’ and ‘helloworld’ with your preferred database username and password in the above command.
Note – cPanel username should be followed by an underscore in the database user otherwise the uapi will not accept the command and will give you an error for the same.
Finally, add the user to the database with this command.
uapi --user=basezap Mysql set_privileges_on_database user=basezap_dbuser database=basezap_website privileges=ALL%20PRIVILEGES
Replace “ALL%20 PRIVILEGES” with the specific privileges that match your preferences, as documented here:
Learn how to install and configure CSF Firewall on Linux. Buy Linux VPS from Oudel Inc.



