LoginSignup
0
0

More than 1 year has passed since last update.

CakePHP4 MAMP下で Migration コマンドが動いてくれない

Last updated at Posted at 2021-06-11

環境

  • CakePHP4.2.6
  • (Cakephp3でも確認済み)
  • PHP7.4.16
  • MAMP

はじめに

MAMP で CakePHP を動かしていたら migration コマンドでエラーを吐いて詰まった。
調べてもなかなか該当するものがなかったので投稿。

目次

1.mamp下でbakeコマンドが使えない?
2.悪いのはmampのソケットの場所だった
3.参考文献

1. mamp下でbakeコマンドが使えない

いつも通りbin/cake migrations migrateとコマンドを叩いたところ以下のようなエラーを吐いて動かない。

Exception: There was a problem connecting to the database: SQLSTATE[HY000] [2002] No such file or directory
In [/Applications/MAMP/htdocs/hogehoge/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php, line 96]

2021-06-11 23:56:11 Error: [InvalidArgumentException] There was a problem connecting to the database: SQLSTATE[HY000] [2002] No such file or directory in /Applications/MAMP/htdocs/hogehoge/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 96
Stack Trace:
- /Applications/MAMP/htdocs/hogehoge/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php:140

/*省略*/

Caused by: [PDOException] SQLSTATE[HY000] [2002] No such file or directory in /Applications/MAMP/htdocs/hogehoge/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 84
Stack Trace:
- /Applications/MAMP/htdocs/hogehoge/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:84

/*省略*/

エラー文を調べたところconfig/app.php の設定値 'host' => 'localhost' を 'host' => '127.0.0.1' にしろと書いてあるので試してみるが治らず・・・。

色々調べてるうちに以下の結論に辿り着いた。

2. 悪いのはMAMPのソケットの場所だった

シンボリックリンクを貼ってみて再び試してみるといけた!

$ ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

3. 参考文献

0
0
0

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
0
0