Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl, DBI, localhost problem

Reply
Thread Tools

Perl, DBI, localhost problem

 
 
Jonas Andersson
Guest
Posts: n/a
 
      01-30-2004
Hi

I run Apache and collect info from my local MySQL database through a
Perl-CGI using DBI. Works fine. However, when I try to write a non-CGI
script (hence not using Apache) to access MySQL, I cannot connect to
the database.

I use

my $username="user2"; my $password="(not shown)";
my $data_source="DBI:mysql:MyDatabase:localhost";
$dbh = DBI->connect($data_source, $username, $password) or die "1";

which works fine when CGI:ed. But when I try this for my non-CGI
script, all I get is

DBI connect('MyDatabase:localhost','user2',...) failed: Access denied
for user: 'user2@localhost' to database 'MyDatabase' at newdeal1a.pl
line 165
error connecting

The username and password are obviously correct, and I can see that
this has got something to do with localhost, but I'm afraid I can't
see what. I have searched FAQs and the net, but I can't find any help.
I'd be most grateful for whatever input I can get for this - I'm sure
the problem is trivial.

Thanks a lot, JA
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-30-2004
On Fri, 30 Jan 2004, Jonas Andersson wrote:

> Hi
>
> I run Apache and collect info from my local MySQL database through a
> Perl-CGI using DBI. Works fine. However, when I try to write a non-CGI
> script (hence not using Apache) to access MySQL, I cannot connect to
> the database.
>
> I use
>
> my $username="user2"; my $password="(not shown)";
> my $data_source="DBI:mysql:MyDatabase:localhost";
> $dbh = DBI->connect($data_source, $username, $password) or die "1";
>
> which works fine when CGI:ed. But when I try this for my non-CGI
> script, all I get is
>
> DBI connect('MyDatabase:localhost','user2',...) failed: Access denied
> for user: 'user2@localhost' to database 'MyDatabase' at newdeal1a.pl
> line 165
> error connecting
>
> The username and password are obviously correct, and I can see that
> this has got something to do with localhost, but I'm afraid I can't
> see what. I have searched FAQs and the net, but I can't find any help.
> I'd be most grateful for whatever input I can get for this - I'm sure
> the problem is trivial.
>
> Thanks a lot, JA



Are you running the non-CGI script on the same server that the CGI script
is running on? If not, then "localhost" refers to two different machines.
One (the CGI's machine) has permissions to the database, the other does
not. Try changing the datasource to
"DBI:mysql:MyDatabase:machine.domain.com" where "machine.domain.com" is
the name of the server that the CGI script works with.

Paul Lalli
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit Ring server to localhost only. RingFinger.new('localhost')apparently doesn't work koicat Ruby 0 07-02-2010 08:01 PM
change from "//localhost:numbers/" to just "//localhost/"? =?Utf-8?B?S2VuTGVl?= ASP .Net 5 02-12-2006 05:14 AM
Localhost isn't localhost EdwardH Java 20 10-01-2005 12:08 AM
Can I Reset the Root from localhost/myproject/ to localhost/ Alex ASP .Net 4 02-08-2005 01:45 PM
HttpModule -- how to intercept urls like http://localhost/abc/def or http://localhost/abc/def/ where abc, def are non virtual dir Jiong Feng ASP .Net 0 11-19-2003 05:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57