Create Database as root

So I’ve managed to log in root and create a cpanel account for a new domain… and I’ve managed to create a database. However I must be missing a step since the only way to access the created database is to log in as root.

Is it possible to create it and assign it to the domain I’ve just created?

Here is what I’ve got:

/// this works, the domain account is created.
$result = $xmlapi->createacct($acct);

I call the following function to create the database which remains owned by root. Although I want it owned by account we just created.


// function generate database

//$master is root password.  $c_user is the account name of the domain we just created.  

function makedabase($c_user, $master){
	//connect  <--works
$link32 = mysql_connect('localhost', 'root', $master) or die(mysql_error());

$dodb = mysql_query("create database {$c_user};",$link32) or die(mysql_error());
$wewe = mysql_select_db("{$c_user}", $link32);
echo 'Database has been created<br>';

So am I doing something wrong? Or is what I’m trying to do just not possible?

Have you tried creating a user account on the server and allowing that user to only be able to interact with the database concerned?

I’ve tried a number of different ways - but none of them seem to show the database in the accounts phpmyadmin. Going to try to call a script I place on the new domain to see if I can get it to work that way.

Does the user account you created in phpmyadmin show ok on the privileges page?

No it doesn’t. Thank you - I’ll have to dig through the api and see if I can grant that with out logging in.

note: you have to call flush privileges in order for any changes to the privileges database (called mysql) to take place.

"When you create accounts with INSERT, it is necessary to use FLUSH PRIVILEGES to tell the server to reload the grant tables. Otherwise, the changes go unnoticed until you restart the server. With CREATE USER, FLUSH PRIVILEGES is unnecessary. " - Mysql manual page.

I used to always forget this command, just saying.