Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel(5.1)のMacローカル環境での 'SQLSTATE[HY000] [2002] No such file or directory'エラー対処

Last updated at Posted at 2016-01-21

初投稿&PHP,Laravel初心者です

LaravelのMacローカル環境でマイグレーションを行った際以下のエラーが発生しました。

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

どうやらMySQLとの接続エラーらしいのですが、database.php.envの設定は一通り終わらせていました。

どうやらdatabase.phpで'unix_socket'を設定しなければいけないようです。

unix_socketはMySQLから

show variables like '%sock%'

すると

+-----------------------------------------+-----------------+ | Variable_name | Value | +-----------------------------------------+-----------------+ | performance_schema_max_socket_classes | 10 | | performance_schema_max_socket_instances | -1 | | socket | /tmp/mysql.sock | +-----------------------------------------+-----------------+

このような画面が出てくるのでこの中の'/tmp/mysql.sock'をdatabase.phpに記述します。

database.php
'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'sample',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'unix_socket' => '/tmp/mysql.sock',
        ), 

もしshow variables like '%sock%'でエラーが出た際はMySQLをアップグレードした上で再起動すると解決できると思います

15
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?