The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SHELL non-root mysql user creation

Discussion in 'General Discussion' started by ammodump, Oct 15, 2006.

  1. ammodump

    ammodump Member

    Joined:
    Nov 28, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  2. ammodump

    ammodump Member

    Joined:
    Nov 28, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  3. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    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:$cppassword@localhost: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.
     
Loading...

Share This Page