Home>
Each version
  • Laravel Framework 5.8.35
  • MySQL 8.0.17
  • Vue 2.5.17
  • vue-axios 2.1.5
What you did

I read and corrected some articles about authentication methods for MySQL8. By the way, I've made some apps using MySQL and Laravel so far.

// .env
DB_CONNECTION = mysql
DB_HOST = 127.0.0.1
DB_PORT = 3306
DB_DATABASE = Database name (confirmed)
DB_USERNAME = tsubasa (confirmed)
DB_PASSWORD = Password (confirmed)

→ This works with Sequel pro, so there seems to be almost no mistake in connection.


>SELECT user, host, plugin FROM mysql.user;
+ ------------------ + ----------- + ------------------ ----- +
| user | host | plugin |
+ ------------------ + ----------- + ------------------ ----- +
| forge |% | caching_sha2_password |
| forge1 |% | caching_sha2_password |
| tsubasa |% | mysql_native_password |
| banana | localhost | caching_sha2_password |
mysql.infoschema | localhost | caching_sha2_password |
mysql.session | localhost | caching_sha2_password |
mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+ ------------------ + ----------- + ------------------ ----- +

I know that it's not good if it's not mysql_native_password, so it is currently only used by tsubasa users.


When you access http://127.0.0.1:8000/api/songs (use Vue, use/api /)

SQLSTATE [HY000] [2054] The server requested authentication method unknown to the client (SQL: select * fromsongs)

will appear.

Similarly, even if you have a post relationship, there is no doubt that i am stuck with the same authority.

Possible cause

At the bottom of the image,

PDOException: :( "PDO :: __ construct (): The server requested authentication method unknown to the client [caching_sha2_password]")
      /Users/tsubanana/Downloads/program/utakan/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
  2 PDO :: __ construct ("mysql: host = 127.0.0.1;port = 3306;dbname = laravel", "root", "", [])
      /Users/tsubanana/Downloads/program/utakan/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

is displayed.

The client [caching_sha2_password] is also written asmysql_native_password
The second point "mysql: host = 127.0.0.1;port = 3306;dbname = laravel", "root" seems to be the default setting, but the user name is set to tsubasa etc. .

I saw Connector.php: 70, which is an error file to fix this, but it seems to be a variable and I can't figure out where to go. .

In other words, there seems to be another .env existence that has been reflected.

I'd be happy if you could teach me somebody.

  • Answer # 1

    .env has been modified so we have to do config: cache but forgot.
    In other words, it seems better not to do it outside the production environment. Please check for details.
    https://blog.capilano-fw.com/?p=3343