Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

What modules do I need to connect Perl to MySQL?

( #7984=categorized question: print w/ replies, xml ) Need Help??
Contributed by little_mistress on Apr 19, 2000 at 04:04 UTC
Q&A  > database programming


Description:

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?

Answer: What modules do I need to connect Perl to MySQL
contributed by BBQ

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.

Answer: What modules do I need to connect Perl to MySQL
contributed by btrott

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.
Answer: What modules do I need to connect Perl to MySQL?
contributed by penguinfuz

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.

Answer: What modules do I need to connect Perl to MySQL?
contributed by Anonymous Monk

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> ~; }

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (7)
    As of 2014-07-13 22:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (252 votes), past polls