How to Create a MySQL Database Using the cPanel API

If you are running cPanel on your server, then you should use the cPanel API to create the database from the command line. Creating the database this way, allows for cPanel to integrate the necessary permissions for each cPanel user to access the databases they are granted access to.

For instance, if you create a database from the command line using MySQL, the database will not appear in the cPanel interface or phpMyAdmin. In this guide, you can learn the commands to create a MySQL database, database user and password, as well as, assign all privileges to the user for the database.

Don’t have time to read the article? Watch our walk-through video.

Create a Database Using cPanel API

  1. Log into your server via SSH.
  2. Run the following command to create the database:uapi --user=exampl3 Mysql create_database name=db_name

    NOTE: Be sure to replace exampl3 with your actual cPanel username and db_name with the actual name you would like to give to the database.

  3. Run the following command to create the database user:uapi --user=exampl3 Mysql create_user name=db_user password=P@s$w0rd123!

    NOTE: Be sure to replace exampl3 with your actual cPanel username, db_user with the actual name you would like to give to the database user, and P@s$w0rd123! to the actual password you would like to assign to this user.

  4. Assign the database user privileges to access the database by running the following command:uapi --user=exampl3 Mysql set_privileges_on_database user=db_user database=db_name privileges=ALL

    NOTE: Be sure to replace exampl3 with your actual cPanel username, db_user with your actual database user, and db_name with the actual name of the database.

cPanel MySQL® Database Wizard

The cPanel MySQL® Database Wizard creates a database, as well as a database user and password. The Wizard also completes the process of assigning privileges to the database user (to use the database as needed). For step-by-step instructions you can refer to our guide: How to Create a MySQL Database in cPanel.

IC
InMotion Hosting Contributor Content Writer II

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+