in reply to Re: Perl Script connecting to Mysql works from command prompt, not from Apache
in thread Perl Script connecting to Mysql works from command prompt, not from Apache

If your mysql.user table is like you originally wrote it.
Mysql info - select * from mysql.user yields: host = localhost user = root password = (none) host = % user = apache password = 77ddghws8w... host = localhost user = apache password = (none) host = 127.0.0.1 user = apache password = (none) host = % Db= test User=(none) select=Y ... host = % Db= Loader User=apache select=Y ... host = localhost Db= Loader User=apache select=Y ... host = 127.0.0.1 Db= Loader User=apache select=Y ...
then perhaps mysql is picking which of the three differing apache it is using differently between the command line and browser... (I know what I want to say but it just isn't coming out properly) ... and that is messing up the permissions.

Since mysql doesn't care who the *actual* user is, but only the hostname, database, username, and password you provide it in your connect, and it picks *which* available user it uses, you may be giving it too much opportunity to choose.

You could try this....

grant select, insert, update, delete on Loader.* to testuser@localhost identified by 'testpass';

And then change your script to use username:testuser and password:testpass. This will give you just one user to worry about and cut down on the potential of mysql picking the wrong user.

Another thing that *could* be happening is your browser connection is not acting as if it is from localhost. That is a reach, as I am sure people who know these things will point out to me...but I have worked on at least one setup where the mysql connection had to be set up as nobody@local.secondary.tld.

To test around that you might want to specify localhost in your connect method.

$database = "Loader"; $hostname = "localhost"; $username = "testuser"; $password = "testpass"; $dbh = DBI->connect("DBI:mysql:$database:$hostname", $user, $password)
mysql assumes localhost and port 3306 if they are not specified btw, but it couldn't hurt to set them

Also, you might want to look at http://www.mysql.com/doc/C/a/Can_not_connect_to_server.html

I am not super familiar with permissions and whatnot, but while mysql may not actually care who the *actual* user is connecting to it is, your file system does.

According to the above mentioned article.... A MySQL client on Unix can connect to the mysqld server in two different ways: Unix sockets, which connect through a file in the file system (default `/tmp/mysqld.sock') or TCP/IP, which connects through a port number. Unix sockets are faster than TCP/IP but can only be used when connecting to a server on the same computer. Unix sockets are used if you don't specify a hostname or if you specify the special hostname localhost

There is the possiblity that this file is set with permissions that do not allow apache to access it, but allow you(the user), to access it on the command line.

Thanks...
EEjack