简体   繁体   中英

SQLSTATE[HY000] [2002] Permission denied Laravel PDO Driver (credentials working via artisan migrate)

I'm having a lot of trouble with the PDO driver on this new installation

This is the error I get when trying to do any db operation triggered by laravel.

ext Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Permission denied (SQL: select * from `users` where `email` = ethan@gmail.com limit 1) in /var/www/html/mypath/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647

What's really strange here, is that PDO is enabled in php, and we're using the same credentials that php artisan migrate used to create the tables (so I know credentials, mysql socket are all working)

This is the PDO error from the stack

at PDO->__construct('mysql:unix_socket=/mnt/volume_sfo2_01/mysql_data/mysqld.sock;dbname=testdb1', 'dbuser1', 'mypassword', array(0, 2, 0, false, false))
in Connector.php line 68

Note that I did move the datadirectory of mysql and thus the change for the socket. This config works running the migrate, so what am I missing to get it working with the laravel PDO driver?

On ubuntu server 16 as well. Nginx + php7.1 apparmor has been disabled additional just for this testing. Any ideas would be greatly appreciated.

I had similar issue on Laravel/Lumen 5.5 / CentOS7 / php71 / mariaDB

using the 'setenforce to test' strategy outlined in the solution here, Permissions Issue with Laravel on CentOS you might want to test for the influence of SElinux.

I was connecting via port 3306 and was able to resolve with insight from this problem report ( https://bugzilla.redhat.com/show_bug.cgi?id=1245295 ) that lead me to

sudo setsebool httpd_can_network_connect_db 1

to make this change permenant you need to add -P switch

sudo setsebool -P httpd_can_network_connect_db 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM