http://www.perlmonks.org?node_id=7984

little_mistress has asked for the wisdom of the Perl Monks concerning the following question: (database programming)

Hello,

It has fallen on my shoulders at work to do investigation into perl's ability with MySQL. Not really having installed the modules that i need to use the MySQL software, and knowing that someone someplace has probably had to do this before. What Perl modules do I need to get it to work properly? There seem to be many many pieces, Such as DBI, DBD, and the MySQL module stuff. Can someone give me a list of what I need?

Originally posted as a Categorized Question.

  • Comment on What modules do I need to connect Perl to MySQL?

Replies are listed 'Best First'.
Re: What modules do I need to connect Perl to MySQL
by BBQ (Curate) on Apr 19, 2000 at 21:22 UTC
    On a side note:
    There are two methods of using Msql-Mysql-modules. You can use it as DBD::mysql (as btrott pointed out), or you can use it in native mode.

    Although you may feel tempted to, I would recommend against using it in native mode. Sure you get a few new features like $sth->query() without having to prepare() and execute(), but in the long run it prooves to be a bad habbit since you can't easily port your applications to other DBMS's...

    Cheers.
Re: What modules do I need to connect Perl to MySQL
by btrott (Parson) on Apr 19, 2000 at 04:20 UTC
    I did this a while ago, and I think I installed the following (in this order):
    • DBI, which is the main interface
    • Bundle::DBD::mysql (the same as Msql-Mysql-modules), which contains the drivers for mSQL and MySQL. You'll need the latter, of course.
    I think that was it, but I don't remember exactly. Use CPAN.pm (perl -MCPAN -e shell), because it makes it a *lot* easier.
Re: What modules do I need to connect Perl to MySQL?
by penguinfuz (Pilgrim) on Feb 06, 2001 at 07:55 UTC
    perl -MCPAN -e shell
    install Bundle::DBD::mysql

    During the installation, you will be prompted for some values, you should take the DEFAULT value for each UNLESS you've disabled the anonymous user access.

    When the installation ask for the username to test with (default is undef), choose "root", and the set the password, (again undef) to whatever you've set the root user's MySQL password to.

    NOTE:The username/password is only for the installation to test, (make test) and if it fails, you can always go into the ~/.cpan/build/$MYSQL_SOURCE directory and *manually*...
    make install

    Assuming you've installed MySQL... 8)
    /usr/bin/mysql_setpermission

    If the previous command works, you've got Perl and MySQL playing together.

Re: What modules do I need to connect Perl to MySQL?
by Anonymous Monk on Oct 17, 2003 at 16:11 UTC
    It's simple, select 'Mysql':
    #!/usr/bin/perl use Mysql; $DBHOST = "localhost"; $DBNAME = "dbname"; $DBUSER = "user"; $DBPASS = "password"; $DB = Mysql->connect($DBHOST, $DBNAME, $DBUSER, $DBPASS); my $qry = $DB->query( qq~SELECT * FROM cds~ ); while( @emps = $qry->fetchrow) { print qq~ $emps[0]<br> ~; }