Introduction
This article aims to assist you with removing databases from the command line using cPanel's build-in UAPI tools.
Forewarning
The actions below to remove databases permanently deletes them from the server, so please check with a Systems Administrator if you are uncertain if a database is necessary for any users on your server.
We do not recommend using the MySQL command line as this breaks certain cPanel functionality, such as the database mapping. Please only use the API or cPanel UI to create or delete the MySQL database and/or users.
Procedure
1. Access your server via ssh as the root user, or log into the WHM and access the terminal from this panel.
2. List the databases for the cPanel user in question. In this example, I've used the cPanel user named 'example.' You can do this by using the UAPI command
uapi --user=example Mysql list_databases
in all UAPI commands, the --user value will always be the cPanel user who owns the database since the cPanel user is named 'example' that will be the argument in this zone.
root@database.server: uapi --user=example Mysql list_databases
---
apiversion: 3
func: list_databases
module: Mysql
result:
data:
-
database: example_test1
disk_usage: 0
users: []
-
database: example_test2
disk_usage: 0
users: []
-
database: example_test3
disk_usage: 0
users: []
-
database: example_test4
disk_usage: 0
users: []
-
database: example_test5
disk_usage: 0
users: []
errors: ~
messages: ~
metadata:
transformed: 1
status: 1
warnings: ~
uapi --user=username Mysql delete_database name=example
root@database.server: uapi --user=example Mysql delete_database name=example_test5
---
apiversion: 3
func: delete_database
module: Mysql
result:
data: ~
errors: ~
messages: ~
metadata: {}
status: 1
warnings: ~
Information on the UAPI's are below from the cPanel documentation website.
Before removing any databases for any users we highly recommend you create backups of the databases using the mysqldump command which has the documentation below from the MySQL developer website. We also have an article below that goes over how to back up all databases on the server.