M
M
Max Richter2015-07-31 11:30:45
MySQL
Max Richter, 2015-07-31 11:30:45

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

What is the problem?
Here is my database.php config in Laravel 5:
'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,
    ],

Here is where the socket and its permissions are:
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

Here are the php.ini settings
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

All the settings given here are absolutely correct, the solution to the problem is below in the comments.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vyacheslav Plisko, 2015-07-31
@AmdY

Do you have the correct data in .env?

N
newpy, 2015-07-31
@newpy

проверить в .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

R
Ramir1, 2015-10-23
@Ramir1

В файле .env добавьте
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
где укажите путь к сокету. Посмотреть путь можно в phpinfo() :-)

Станислав Еременко, 2017-07-06
@c01nd01r

Добавлю для себя, что в 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 question

Ask a Question

731 491 924 answers to any question