How to create MySQL user and database from command line of a cPanel server

Tags: cPanelhackMySQL

Published on: June 2, 2015 by Arnold Pablo

How to create MySQL user and database from command line of a cPanel server


cPanel has made everyone’s life easy. But a few sysadmins won’t get the kick of “IT” when they work on a cPanel server. cPanel is fun and is defining professionalism in their support, Paper lantern UI and in every other area, I can think of, as each day passes. The MySQL create user and create database functions are available in the cPanel frontend.

But today I needed to create a DB from the backend, I am fully aware that APIs exist for my job, but needed something quick to create the MySQL db from the backend. I remember issuing a command similar to /scripts/createmysqldb or so, but didn’t see it today. Guess cPanel removed it. Here it goes – the three step process

Step 1.
Let’s create the DB first.

root@server [/etc]# sudo -u cp-username-of-the-domain /usr/local/cpanel/bin/cpmysqlwrap  ADDDB cp-username-of-the-domain_database

It will show a message saying similar to below, assuming you have given cp-username-of-the-domain_database as testuser_db

info [cpmysqladmin] Creating MySQL database testuser_db for user testuser

Step 2.
Now create the DB user.

root@server [/etc]# sudo -u cp-username-of-the-domain /usr/local/cpanel/bin/cpmysqlwrap  ADDUSER cp-username-of-the-domain_user

Above command should show an output similar to below. Assumption again, cp-username-of-the-domain_user is testuser_user

info [cpmysqladmin] Creating MySQL virtual user testuser_user for user testuser

Step 3.
Finally, adding all privileges for the user to the DB.

root@server [/etc]# sudo -u cp-username-of-the-domain /usr/local/cpanel/bin/cpmysqlwrap  ADDUSERDB 'cp-username-of-the-domain_user' 'cp-username-of-the-domain_database' ALL

Surprisingly, this won’t give you any console outputs. But you can check the existence of DB by logging to MySQL prompt.

Get 24/7 expert server management

Category : cPanel, Linux, MySQL

Arnold Pablo

Arnold Pablo

Technology always fascinated me and continues to do so. I started my career back in 2004 as a Junior System Admin and worked in various capacities both in technical and managerial roles. I love to experiment and try out new OSS projects and in free time, go for cycling to the interiors of God's own country, Kerala!

You may also read:


Add new commentSIGN IN

Let's Connect


Your Cart

Cart is empty.

Send this to a friend