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.
Create a Database Using cPanel API
- Log into your server via SSH.
- 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 anddb_name
with the actual name you would like to give to the database. - 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, andP@s$w0rd123!
to the actual password you would like to assign to this user. - 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, anddb_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.