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


In reply to Re: Re: Perl Script connecting to Mysql works from command prompt, not from Apache by eejack
in thread Perl Script connecting to Mysql works from command prompt, not from Apache by gary kuipers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.