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

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

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

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

1回答

489閲覧

Laravel $php artisan migrateのエラー

end.ne

総合スコア9

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

0グッド

2クリップ

投稿2018/09/27 21:19

編集2018/09/28 02:20

Laravelで$php artisan migrateを打った時エラーが出ました。
ローカル環境で作業しています。
HPで参考サイトを見ながら作業をしています。

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

Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user '〇〇〇'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = 〇〇〇 and table_name = migrations) at /Users/**/Desktop/PHP/Laravel/Project/〇〇〇/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 PDOException::("SQLSTATE[HY000] [1045] Access denied for user '〇〇〇'@'localhost' (using password: YES)") /Users/**/Desktop/PHP/Laravel/Project/〇〇〇/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68 2 PDO::__construct("mysql:unix_socket=/tmp/mysql.sock;dbname=〇〇〇", "〇〇〇", "〇〇〇", []) /Users/**/Desktop/PHP/Laravel/Project/〇〇〇/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68 Please use the argument -v to see more details.

該当のソースコード

2018_09_ _182535_create_posts_table.php

<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->string('cat_id'); $table->text('content'); $table->unsignedInteger('comment_count'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('posts'); } }

2018_09_ _182609_create_categories_table.php

<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateCategoriesTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('categories', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('categories'); } }

2018_09_ _182620_create_comments_table.php

<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateCommentsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('post_id'); $table->string('commenter'); $table->text('comment'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('comments'); } }

database.php

<?php return [ /* |-------------------------------------------------------------------------- | Default Database Connection Name |-------------------------------------------------------------------------- | | Here you may specify which of the database connections below you wish | to use as your default connection for all database work. Of course | you may use many connections at once using the Database library. | */ 'default' => env('DB_CONNECTION', 'mysql'), /* |-------------------------------------------------------------------------- | Database Connections |-------------------------------------------------------------------------- | | Here are each of the database connections setup for your application. | Of course, examples of configuring each database platform that is | supported by Laravel is shown below to make development simple. | | | All database work in Laravel is done through the PHP PDO facilities | so make sure you have the driver for your particular database of | choice installed on your machine before you begin development. | */ 'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), 'prefix' => '', ], 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', '〇〇〇'), 'username' => env('DB_USERNAME', '□□□'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', '/tmp/mysql.sock'), 'charset' => 'utf8', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => 'InnoDB', ], ], /* |-------------------------------------------------------------------------- | Migration Repository Table |-------------------------------------------------------------------------- | | This table keeps track of all the migrations that have already run for | your application. Using this information, we can determine which of | the migrations on disk haven't actually been run in the database. | */ 'migrations' => 'migrations', /* |-------------------------------------------------------------------------- | Redis Databases |-------------------------------------------------------------------------- | | Redis is an open source, fast, and advanced key-value store that also | provides a richer set of commands than a typical key-value systems | such as APC or Memcached. Laravel makes it easy to dig right in. | */ 'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DB', 0), ], 'cache' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_CACHE_DB', 1), ], ], ];

.esv

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=〇〇〇 DB_USERNAME=□□□ DB_PASSWORD=

.env.example

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=〇〇〇 DB_USERNAME=□□□ DB_PASSWORD=

試したこと

調べるときに「php Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user」と検索しました。
.サイトを見て、envの値を設定し直した結果が上記の「.esv」「.env.example」ですがエラーは変わりませんでした。
・mysql> show variables like '%sock%';
でコマンドをうち、socket を調べたところ「 /tmp/mysql.sock 」と表示され他ので、「'unix_socket' => env('DB_SOCKET', '/tmp/mysql.sock'),」と入れています

mysql> show variables like '%sock%'; +-----------------------------------------+-----------------+ | Variable_name | Value | +-----------------------------------------+-----------------+ | performance_schema_max_socket_classes | 10 | | performance_schema_max_socket_instances | 322 | | socket | /tmp/mysql.sock | +-----------------------------------------+-----------------+

・似たような事例があり、調べましたがエラーが解決しませんでした。
自分が理解しきれず、また調べ肩が悪いと思うのですが、ご教授お願いします。

*補足

・MAMPは使用していません。
・Laravelのバージョンは「Laravel Framework 5.7.6」です。
・〇〇〇は全て同じスペルです。
・□□□は全て同じスペルです。
・'password' => env('DB_PASSWORD', ''),パスワードは設定していません。

追記・修正依頼への返信

*mts10806さん

>失礼しました。使用はMacでローカルサーバーはHomebrewを使用しています。
また、PHP及びMySQLのバージョンは「PHP-> 7.1.16 」「MySQL->Ver 14.14 Distrib 5.7.21, for osx10.13」です。
参考サイトはhttps://manablog.org/laravel_bulletin_board/です。
DB名とユーザー名は変更しています。
ただ、「MySQLは最近のものであればパスワード設定必須」と言うのが明確な答えを見つけられすにいます。
*dyoshikawaさん
>失礼しました。記述ミスでして、ファイル名は「.env」です。

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

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

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

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

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

m.ts10806

2018/09/27 23:52

何を参考にしましたか?ローカルサーバーはMAMPでなければ何でしょうか?WindowsであればXAMPPでしょうか。それとも個々に入れたのでしょうか。PHPおよびMySQLのバージョンもあわせて情報を追記してください。あとMySQLは最近のものであればパスワード設定必須だったような記憶があります。そのあたりは心当たりありませんか?
退会済みユーザー

退会済みユーザー

2018/09/28 01:29

まず.esvというファイル名が誤っているので.envに修正して下さい。
end.ne

2018/09/28 02:00

mts10806さん>失礼しました。使用はMacでローカルサーバーはHomebrewを使用しています。また、PHP及びMySQLのバージョンは「PHP-> 7.1.16 」「MySQL->Ver 14.14 Distrib 5.7.21, for osx10.13」です。参考サイトはhttps://manablog.org/laravel_bulletin_board/です。DB名とユーザー名は変更しています。ただ、「MySQLは最近のものであればパスワード設定必須」と言うのが明確な答えを見つけられすにいます。
end.ne

2018/09/28 02:02

dyoshikawaさん>失礼しました。記述ミスでして、ファイル名は「.env」です。
m.ts10806

2018/09/28 02:05

こちらのコメント欄はデフォルト非表示であるため、適宜質問本文に追記してください
end.ne

2018/09/28 02:21

修正しました。
guest

回答1

0

MySQLに接続出来てないような気がします。
(私も超が付く初心者ですが。回答失礼します。)

Homebrew ->
Laravel/Homestead の事でしょうか?
またローカル環境はvagrantでしょうか?
そうであるなら、

1
/Homestead/Homestead.yaml

databases: - DB名

を変更。

2 プロジェクト 内の.env変更。

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=DB名 DB_USERNAME=User DB_PASSWORD=pass

3 ~/Homestead で

vagrant reload
vagrant up --provision
vagrant ssh

sshで仮想サーバに入り

mysql -u Uset -p

DBを作成、

create database DB名

でどうでしょうか。

投稿2018/09/28 03:07

sprn

総合スコア19

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

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

end.ne

2018/09/28 04:32 編集

sprnさんありがとうございます。 HomebrewはHomesteadとは別のもので、WEBサイトをローカルで開発できるようにする為に、PHP7.1.16, MySQL 5.7.21 Apache 2.4.33をHomebrewを使って導入しています。 https://www.findxfine.com/server/mysql/995560723.html https://qiita.com/park-jh/items/78efe8c3c93cf533aafa ただ、mySQLとの接続がうまく言っていない可能性があるかもしれません、 Homebrewをやり直して見ますが、Homesteadのやり方も試して見ます!
退会済みユーザー

退会済みユーザー

2018/09/29 06:40

homesteadでdatabaseを作成する必要はないですよ。最初からhomesteadというdatabaseが用意されています。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問