Answer the question
In order to leave comments, you need to log in
Why does [pdoexception] sqlstate[hy000] [2002] no such file or directory exit in Laravel 5?
Installed nginx, php-fpm, mariadb, Laravel 5 on vps.
Laravel artisan commands work, but db commands don't work:
I enter command I get an php artisan migrate:install
error
[pdoexception] sqlstate[hy000] [2002] no such file or directory
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'database' => env('DB_DATABASE', 'demo'),
'username' => env('DB_USERNAME', 'demo'),
'password' => env('DB_PASSWORD', 'dq2'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'unix_socket' => '/var/lib/mysql/mysql.sock',
'strict' => false,
],
php -i | grep pdo
/etc/php.d/20-pdo.ini,
/etc/php.d/30-pdo_mysql.ini,
/etc/php.d/30-pdo_sqlite.ini,
API Extensions => mysql,mysqli,pdo_mysql
pdo_mysql
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
pdo_sqlite
ls -l /var/lib/mysql/mysql.sock
srwxrwxrwx. 1 mysql mysql 0 июл 31 10:01 /var/lib/mysql/mysql.sock
mysql.default_socket = /var/lib/mysql/mysql.sock
mysqli.default_socket = /var/lib/mysql/mysql.sock
pdo_mysql.default_socket = /var/lib/mysql/mysql.sock
Answer the question
In order to leave comments, you need to log in
проверить в .env DB_HOST заменить на 127.0.0.1, возможно mysql создает сокет в /var/run/mysql/mysql.sock
php.ini тогда так:
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock
Или как узнать сокет:
$ mysql -uroot -p
mysql> show variables like '%sock%';
покажет путь сокета, останется прописать в php.ini
В файле .env добавьте
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
где укажите путь к сокету. Посмотреть путь можно в phpinfo() :-)
Добавлю для себя, что в OctoberCMS под MAMP нужно было добавить в site.ru/config/database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', // !!!
'port' => 3306,
'database' => 'db',
'username' => 'user',
'password' => '123',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question