はじめて Laradock を利用して開発環境の構築をしています。
localhost
にアクセスすると Laravel の文字が表示されました。
次に php artisan migrate
としてマイグレーションを実行すると下記のエラーが表示されました。
In Connection.php line 664: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) In Connector.php line 67: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client In Connector.php line 67: PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
ググると MySQL 8 系で認証形式の変更があったことが原因なのかと思います。
(解決策として適切かわかりませんが)ここ の rockerbom さんの方法で解決できるのかと試しました。
下記は引用です。
- add default authentication plugin to laradock/mysql/my.cnf
[mysqld] default_authentication_plugin= mysql_native_password
- update content file mysql/docker-entrypoint-initdb.d/createdb.sql like:
CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpass'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; CREATE USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpass'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION; # CREATE DATABASE IF NOT EXISTS `yourdb` COLLATE 'utf8_general_ci' ; GRANT ALL ON `yourdb`.* TO 'admin'@'%' ; FLUSH PRIVILEGES ;
important note: remove old user, database and recreate again by above script.
- Remove mysql container and re-run it.
- php artisan migrate is done :)
引用: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
上記を参考に下記のように行いました。
手順1
まず、laradock/mysql/my.cnf
に下記を追記しました。
[mysqld] default_authentication_plugin= mysql_native_password
手順2
次に laradock/mysql/docker-entrypoint-initdb.d/
を確認しましたが、 createdb.sql.example
しかなかったので、コピペして createdb.sql
にリネームしました。
createdb.sql
の中身は下記にして保存しました。
CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpass'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; CREATE USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpass'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION; # CREATE DATABASE IF NOT EXISTS `yourdb` COLLATE 'utf8_general_ci' ; GRANT ALL ON `yourdb`.* TO 'admin'@'%' ; FLUSH PRIVILEGES ;
手順3
docker もはじめて触ったのでここが謎でしたが、ぐぐりながら下記のようにやりました。
# docker の停止 docker-compose stop # 停止しているコンテナの確認(mysqlのコンテナIDを確認) docker ps -a # mysqlコンテナの削除 docker rm [コンテナID] # 新たにmysqlコンテナの作成 # docker-compose up mysql
上記のように行い、再度 php artisan migrate
をしましたが、同じくエラーが表示されました。
エラーを解消するにはどのようすれば、よろしいでしょうか。
ご存知の方いれば、教えてくださいm(__)m
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。