Published on: June 2, 2015 by Arnold Pablo
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
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
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
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.
Category : cPanel, Linux, MySQL