in reply to Using mysql with perl

You don't need to move anything. Let the MySQL engine deal with the db files.

In tutorials there is the answer to your question.
Check Reading from a database for details.

If you've read Dubois's book, I wonder what you'd need more, but here goes: (untested)

#!/usr/bin/perl -w use strict; use DBI; my $database = 'test'; my $username = 'username'; my $password = 'secret'; my $dbh=DBI->connect("dbi:mysql:$database", $username,$password, {RaiseError=>1}) or die "can't\n"; #if you get this far, you're connected # and you can list the tables in your db print "$_\n" for $dbh->tables; $dbh->disconnect();

Update

Did you set a user and password in MySQL, or are you running as root without a password? (default out-od-the box).

If that's the case, you should authorize a new user with a password:

use mysql; set password=password('rootpassword'); update user set password=password('rootpassword') where user='root'; delete from user where password=''; grant all privileges on testdatabase.* to kiat identified by 'yourpassword'; flush privileges;

Then log in as 'kiat' (mysql -u kiat -p) and you should be able to use that db, and also the script should work.

For more info, see the appropriate docs.

Replies are listed 'Best First'.
Re: Re: Using mysql with perl
by kiat (Vicar) on Jun 07, 2003 at 12:30 UTC
    Thanks, mahi! I saved your code as test2.cgi and ran it from the browser. I don't see any output. Is it supposed to produce any output? I installed mysql quite a while ago and I'm not even sure if I had set a username and password. Is there a way to check?
      Kiat,

      Don't try to run it from the browser (i.e. via CGI) yet! Does it work from the command-line first? You have to take things one step at a time. So, first you need to figure out: can you connect to the mysql db manually, what password and user-name have you setup, etc.. This may not be a PERL problem at all! Also, if you don't know the user/password you may seriously want to consider reinstalling MySQL again so that you know exactly how it is set up.

      Hope it helps!
      -Tats