質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

2028閲覧

初学習者cakephp公式チュートリアル bin/cake bake modelエラー: SQLSTATE[HY000] [2002]

YuhiUsui

総合スコア11

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2020/11/23 05:23

前提・実現したいこと

公式チュートリアルcmsを進めていたのですがbakeしようといた際にエラー発生
解決し先に進みたいです
該当ページ

発生している問題・エラーメッセージ

はじめのエラー (base) perrymb:cms a0000$ pwd /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms (base) perrymb:cms a0000$ bin/cake bake model users One moment while associations are detected. Exception: Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory In [/Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver.php, line 140] 2020-11-23 05:07:49 Error: [Cake\Database\Exception\MissingConnectionException] Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory in /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver.php on line 140 Exception Attributes: array ( 'driver' => 'Mysql', 'reason' => 'SQLSTATE[HY000] [2002] No such file or directory', ) Stack Trace: - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php:178 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Schema/SchemaDialect.php:47 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php:230 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:53 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Connection.php:399 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Utility/TableScanner.php:65 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:1060 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:191 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:122 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:98 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:81 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/BaseCommand.php:179 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:335 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:171 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/bin/cake.php:12 Caused by: [PDOException] SQLSTATE[HY000] [2002] No such file or directory in /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver.php on line 132 Stack Trace: - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver.php:132 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Core/Retry/CommandRetry.php:70 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver.php:138 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php:178 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Schema/SchemaDialect.php:47 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php:230 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:53 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Database/Connection.php:399 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Utility/TableScanner.php:65 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:1060 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:191 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:122 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:98 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/bake/src/Command/ModelCommand.php:81 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/BaseCommand.php:179 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:335 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:171 - /Users/a0000/.bitnami/stackman/machines/xampp/volumes/root/htdocs/cms/bin/cake.php:12

該当のソースコード

php

1config/app.php 2'Datasources' => [ 3 4 'default' => [ 5 'className' => 'Cake\Database\Connection', 6 'driver' => 'Cake\Database\Driver\Mysql', 7 'persistent' => false, 8 'encoding' => 'utf8mb4', 9 'timezone' => 'UTC', 10 'cacheMetadata' => true, 11 12 13 'quoteIdentifiers' => false, 14 15 16 'unix_socket' => '/opt/lampp/var/mysql/mysql.sock', 17 ],

php

1 2config/app_local.php 3'Datasources' => [ 4 'default' => [ 5 'host' => 'localhost', 6 /* 7 * CakePHP will use the default DB port based on the driver selected 8 * MySQL on MAMP uses port 8889, MAMP users will want to uncomment 9 * the following line and set the port accordingly 10 */ 11 //'port' => 'non_standard_port_number', 12 13 'username' => 'root', 14 'password' => '', 15 16 'database' => 'cake_cms', 17 /* 18 * If not using the default 'public' schema with the PostgreSQL driver 19 * set it here. 20 */ 21 //'schema' => 'myapp', 22 23 /* 24 * You can use a DSN string to set the entire configuration 25 */ 26 'url' => env('DATABASE_URL', null), 27 'unix_socket' => '/opt/lampp/var/mysql/mysql.sock', 28 ],

試したこと

CakePHP3.8でBakeできない場合(DB接続エラー)
こちらが私のケースに当てはまっている気がしましたがMAMPなので下を試しました。
結果がソースコードとエラーメッセージになります
XAMPP環境 海外質問サイト

補足情報(FW/ツールのバージョンなど)

cakephp4, xampp, phpmyadmin

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nojimage

2020/11/24 11:41

bin/cakeコマンドは、仮想マシン内で実行していますか? unix_socket のパスは正しいですか?
YuhiUsui

2020/11/26 05:26

ご指摘ありがとうございます(お返事遅れてすみません。。。) ターミナルでssh接続してから実行することでうまく行きました。 socketのパスは正しかったようです。 xamppがvmバージョンであるということについての理解が乏しく nojimageさんが指摘していただたい内容と合わせて理解が深まりました。
guest

回答1

0

自己解決

仮想マシンで実行することでうまく行きました。
環境構築への理解が足らなかったようです。

投稿2020/11/26 05:27

YuhiUsui

総合スコア11

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問