Daniel R. Daniel R. - 1 year ago 51
Bash Question

Creating Databases/Users Through Code/Command server with WHM/Cpanel

I am trying to write a PHP/Shell command that creates a database on a WHM/cPanel server. Here is what I have tried:
- Accessed SSH through Putty
- Connected to mysql server using

mysql -p

- Ran the command
create database cpaneluser_newdatabase;

However, I get the following error:

Access denied for user 'cpanel_username'@'localhost' to database

I need a way to create a database, a user, and assign a database privileges to that user. Pretty much the exact same process we do through the cPanel interface, but through code/command.

Note that I have root/WHM access.

Access denied for user 'cpanel_username'@'localhost' to database 'cpaneluser_newdatabase'

means User: cpanel_username , accessed at localhost ,has no privileges to access database cpaneluser_newdatabase;

try to login the mysql with root, and grant privileges to ;

use grant all on cpaneluser_newdatabase.* to cpanel_username@'localhost'


cpanel_username@'localhost' is very strange....

better use the mysqlclient like this:

mysql -u<username> -p