#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    79
    Rep Power
    15
    Who knows the statement to create a MySQL database using PERL+DBI.
    The method using PHP is :
    $result=mysql_create_db($dbname);
    But I don't know the method of PERL+DBI
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    33
    Rep Power
    16
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Creating a new Database through Perl DBI


    hi,

    I am also facing a problem in creating a new database through the Perl DBI. I am using DBD-mysql. I know that the command to create a database in mysql is CREATE DATABASE DATABASE_NAME; , but the problem is I dont know, how to create it through the perl script using DBI.

    Can anyone please help me out? Is it actually possible to create a database like that?

    Thanks,
    Pooja
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0
    Originally Posted by poojasreejith
    hi,

    I am also facing a problem in creating a new database through the Perl DBI. I am using DBD-mysql. I know that the command to create a database in mysql is CREATE DATABASE DATABASE_NAME; , but the problem is I dont know, how to create it through the perl script using DBI.

    Can anyone please help me out? Is it actually possible to create a database like that?

    Thanks,
    Pooja
    Hello Pooja,

    Perhaps you should just connect to the standard 'mysql' db that
    holds the 'db' and 'users' tables, then create the database using
    '$dbh->do' and then add permissions to the 'mysql' db 'db' and
    'users' tables so the database can be accessed via the new
    permissions set in the 'mysql' db...

    Have a nice one

    William.
  8. #5
  9. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,252
    Rep Power
    1810
    It's too late. He's been fired already.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    159
    Rep Power
    208
    William, real solution is to use Server Administration methods in DBD::mysql.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0
    Here's the real and easy solution.

    Just leave the database out:

    So do this:
    $dbh = DBI -> connect("dbi:mysql::$host", $user, $password);
    $dbh -> do("CREATE DATABASE $database");

    instead of this:
    $dbh = DBI -> connect("dbi:mysql:$database:$host", $user, $password);

IMN logo majestic logo threadwatch logo seochat tools logo