Linux connecting to mysql PHP

879 views Asked by At

I have been trying to connect to mysql all evening using PHP. I know for a fact the username and password are correct as I have tried 3/4 and I know the permissions are set correctly in the database.

If I remote onto this machine and enter the exact same details into the commandline then i can connect to the database without issue.

The problem only seems to be with MYSQL and PHP.

A little more info:

I am trying to run a PHP app on the same server as the mysql database is on. The user has full grant permissions on the local machine. The error i am receiving is :

Fatal error: Attempt to connect to database kmc_cms on

The server is set so no remote access to mysql is available.

3

There are 3 answers

0
Matt Seymour On BEST ANSWER

I found out the issue. Within the mysql database config file there was an error which resulted in the connection allowing users from local host access only. Even though the PHP scripts were connecting using localhost it just would not authenticate. Hence I could log in using command line and not using PHP or other applications.

0
Mithrandir On

Have you enabled remote access for the user you're trying to connect with in mysql?

2
ethrbunny On

In your question you don't show whether you're trying IP or localhost.

Do a

show grants for <username>;

and see if the connection you're trying is even allowed.