Think about Loose Coupling | |
PerlMonks |
Perl Script connecting to Mysql works from command prompt, not from Apacheby gary kuipers (Beadle) |
on Apr 15, 2001 at 04:21 UTC ( [id://72626]=perlquestion: print w/replies, xml ) | Need Help?? |
gary kuipers has asked for the wisdom of the Perl Monks concerning the following question: I am having problems connecting to MySQL from Perl scripts that are run from the apache web server. These problems don't exist when running the same scripts from the command prompt. It's almost certainly not a Perl problem, but someone may have run into this problem and may be able to help.
Pertinent information:
Apache httpd.conf, section 2 has: There is no (apparent) mysql.cnf file in the system
Observed Behaviour:
script $who=`whoami`; print "$who"; ==> reports "apache" as the user, therefore:
if ( $dbh = DBI->connect("DBI:mysql:$INI{DBname}",$INI{DBuser},$INI{DBpass}) )
the same is true if password is left blank Observation: Users that can connect to mysql from the command prompt and scripts run from the command prompt can access the MySQL databases, whereas those run from the apache web server cannot connect. Presumption: The error that is being generated by the DBI->connect() statement is a MySQL error, not a system error. The $@ variable is null in this case.
Thoughts: It can't be that mysql "rescues" a bad login from prompt(in this case mysql -u apache) by substituting the user from which it was executed, because an apache login bombed when trying to "use mysql", so mysql clearly believed the user was "apache". It is not a MySQL password issue, as shown by the fact that command prompt "mysql -u apache" works, as does the execution of a script from the command prompt even though it has no password in the DBI->connect() statement. The password being blank for apache from the command prompt did not matter. This means that the user table is using one of the more specific apache@localhost or apache@'127.0.0.1' entries rather than the general apache@% This further implies that a login into MySQL with user name "apache" and no password should work. Is it only the user table that allows access? Per the MySQL documentation 6.9: "The user table scope fields determine whether to allow or reject incoming connections.", so it would appear so. Is this access based on the logged in user (in this case "apache" from whe web server) or is it based on the information supplied to the DBI->connect() statement? The incoming CGI request is user system user apache (as shown by the 'whoami' in the script. Additionaly the specified user is apache (in the DBI->connect() statement). Since both are "apache" and a password is (presumably) not required ...? Stumped!
Back to
Seekers of Perl Wisdom
|
|