SHELL non-root mysql user creation

ammodump

Member
Nov 28, 2005
5
0
151
Hi

From the shell, with an account with SSH, but non-root, how do I create a mysql user, pass, and database.

I am writing a script to automaticly install and configure some software... how do I get the shell to prompt to enter a user with a password and create the db?

When, I try:

ammodump @ my.com [~/public_html/pnsetup_temp]# mysql --user=$USER mysql
ERROR 1045 (28000): Access denied for user 'me'@'localhost' (using password: NO)


ammodump @ my.com [~/public_html/pnsetup_temp]# mysql --user=$USER -p mysql
Enter password:
ERROR 1044 (42000): Access denied for user 'ammodump'@'localhost' to database 'mysql'


TIA,
Dave
 

ammodump

Member
Nov 28, 2005
5
0
151
Okay, if I have cpanel, I can create a mysql db, user, and password.

How is it that I can use the shell to access to cpanel functions to create the mysql db, user, and password.

I understand normally, one needs root access to create these, but cpanel allows me to do it without root, is there a way to emulate this through the shell, with non root access?

If so, how?

TIA,

Dave
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
It's only possible because cPanel runs as root so it has access to create the databases. That's how it's able to limit the number of databases per user and control the naming of databases.

The only way I can think of would be to generate an HTTP request to cPanel. In php, try something like this:

PHP:
<?

function create_db($db_name){
$cpusername = "ammodump";
$cppassword = "1234";
$cpmysql_url = "http://$cpusername:[email protected]:2082/frontend/xcontroller/mysql/sqladded.html";
$result = file_get_contents("$cpmysql_url?db=$db_name");
// parse the result and return it?
}
?>
If you have root access, you could write a program that runs as root (suexec) to create databases for any user, but it could pose a security risk.