autoloader Posted May 19, 2015 Share Posted May 19, 2015 Hello, Just reinstalled / upgraded a Fedora Core server with FC 21, MySQL 5.7.7 and PHP 5.6.8. After the installation I restored a database and added/granted access to the neccessary users. But when running a PHP script in CLI mode I'm not able to connect to the database using mysql_connect. It say "Permission denied". but using 'mysql -h <host> -u <user> -p <database>' on the same machine gives me the access. (<host>, <user>, <database> and the password is the same as Any suggestions how to fix this? mysql> grant all privileges on foobar.* to 'foo'@'localhost' identified by 'someSecretPassword'; mysql> flush privileges; In the PHP script: $con = mysql_connect("localhost", "foo", "someSecretPassword"); // here it fails with "Permission denied". $ mysql -h localhost -u foo -p foobar Password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 49 Server version: 5.7.7-rc-log MySQL Community Server (GPL) ... Quote Link to comment Share on other sites More sharing options...
requinix Posted May 19, 2015 Share Posted May 19, 2015 MySQL doesn't have a message that says "Permission denied". What's the rest of the code? Quote Link to comment Share on other sites More sharing options...
autoloader Posted May 19, 2015 Author Share Posted May 19, 2015 This is my code: $dbh = @mysql_connect($dbhost, $dbuser, $dbpass); if (false === $dbh) { $err = @mysql_error(); if ($triggerError) { throw new Exception("Could not connect to db: $err\n"); } } But perhaps you are right. It might be PHP that say I do not have access to mysql_connect! It this a 'new feature' in php 5.7 ??? I have never ever experienced such a problem. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 19, 2015 Share Posted May 19, 2015 (edited) Stop using @ error suppression. You should get an error message now: $dbh = mysql_connect($dbhost, $dbuser, $dbpass); if (false === $dbh) { $err = mysql_error(); if ($triggerError) { throw new Exception("Could not connect to db: $err\n"); } } [edit] For whatever reason, indentation isn't working. [/edit] Also, try using $dbhost = "127.0.0.1", see if that makes a difference. And there is no such thing as PHP 5.7. Edited May 19, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
autoloader Posted May 20, 2015 Author Share Posted May 20, 2015 Sorry, php 5.6 as I wrote in my first posting (5.7 was the Mysql version). 127.0.0.1 did work - thanks. Why did I not think about that in the first time. Seems like PHP does not resolve localhost to 127.0.0.1 while in the shell localhost seem to be OK. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 20, 2015 Share Posted May 20, 2015 Actually it's something else. Using "localhost" clues the MySQL driver to use a socket, which is practically a file on the machine. Using "127.0.0.1" forces a TCP connection, which should definitely work. So your mysqld server daemon may not be creating the socket with the right permissions. Check your MySQL setting to see what it's doing. Also find the socket file itself - it probably doesn't have read (or execute?) permissions set for your user. Simply restarting MySQL may fix it too. Quote Link to comment Share on other sites More sharing options...
autoloader Posted May 20, 2015 Author Share Posted May 20, 2015 The permissions on the mysql.sock file seem to be OK: [root@anakin etc]# cd /tmp [root@anakin tmp]# ls -l m* srwxrwxrwx 1 mysql mysql 0 May 20 12:34 mysql.sock -rw------- 1 mysql mysql 6 May 20 12:34 mysql.sock.lock [root@anakin tmp]# cd / [root@anakin /]# ls -ld tmp drwxrwxrwt. 8 root root 4096 May 20 16:44 tmp Quote Link to comment Share on other sites More sharing options...
requinix Posted May 20, 2015 Share Posted May 20, 2015 The socket is in /tmp? Odd place. It's normally under /var/lib/mysql. Is the client side definitely set up to look there for the socket file? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.