Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    Default Default Automatically create mysql user and database for new WHM accounts?

    Is there a way to set up WHM so when a new account is created it automatically creates a MySQL account too, and ideally a new database for the user?


    In the following thread Automatically create mysql user and database for new WHM accounts?
    The user told us that we need to create and place the script inside "postwwwacct" folder.

    I have few question :
    1) Is this going to be a PERL script.
    2) Can someone please pass a simple code sample which creates the Database,DB user, Password. DB user should correspond to the current user account.

    Thanks in advance...

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    2

    Default Re: Default Automatically create mysql user and database for new WHM accoun

    This would be the holy grail for me too, I've wasted hours searching for a simple code sample.

    Why on Earth isn't this a standard option in WHM?

  3. #3
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Sep 2007
    Posts
    139

    Default Re: Default Automatically create mysql user and database for new WHM accoun

    The following is an old example I wrote that does what you are asking. It would be better to change it to call the api calls directly instead of make a GET request to localhost though.

    Code:
    #!/usr/bin/perl
    
    use LWP::UserAgent;
    
    if ($#ARGV > 1) {
            open(AHASH, "/root/.accesshash");
            my @access = <AHASH> ;
            close AHASH;
            my $hash = join("\n", @access);
            $hash =~ s/\n//g;
            my $dbuser = "cpanel1";
            my $dbpass = "somesecurepass";
            my $dbname = "cpanel1";
            my %OPTS = @ARGV;
            my $user = $OPTS{'user'};
            my $auth = "WHM root:" . $hash;
            my $ua = LWP::UserAgent->new;
    
            #add database
            my $request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=$dbname" );
            $request->header( Authorization => $auth );
            my $response = $ua->request($request);
    
            #add database user
            $request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduser&cpanel_xmlapi_apiversion=1&arg-0=$dbuser&arg-1=$dbpass" );
            $request->header( Authorization => $auth );
            $response = $ua->request($request);
    
            #add user to database
            $request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduserdb&cpanel_xmlapi_apiversion=1&arg-0=$user\_$dbname&arg-1=$user\_$dbuser&arg-2=ALL" );
            $request->header( Authorization => $auth );
            $response = $ua->request($request);
    
    
    }

Similar Threads & Tags
Similar threads

  1. [whm plugin] create database for user
    By kris.x15 in forum cPanel Developers
    Replies: 1
    Last Post: 11-12-2010, 11:21 AM
  2. Automatically create mysql user and database for new WHM accounts?
    By joachim.n in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 06-19-2009, 11:14 AM
  3. mySQL user which can create new database
    By awa in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-23-2008, 04:58 AM
  4. Create MySQL Database & User via Shell
    By Arhineus in forum Database Discussions
    Replies: 1
    Last Post: 10-12-2007, 12:10 PM
  5. Looking for script to create accounts, files AND database automatically
    By infocom in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 11-22-2006, 10:31 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube