LoginSignup
3
1

More than 5 years have passed since last update.

macでLaravelでmysql8を使う (mysql8の認証プラグインの変更)

Last updated at Posted at 2018-10-04

Laravelでデフォルトのmysql8を使うと認証プラグインのパスワード暗号化の違いからマイグレーションでエラーになるらしい。

そうならないためにあらかじめ認証プラグインを変更しておこう。

mysql8の認証プラグインの変更

Server version: 8.0.12 Homebrew

$ mysql -uroot -p

# 現状のプラグインを確認する

mysql> select user, host, plugin from mysql.user;

+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)

# プラグインを変更する
# caching_sha2_password から mysql_native_password に変更する

mysql> ALTER USER 'root'@'localhost' 
IDENTIFIED WITH mysql_native_password 
BY 'hogefugapiyoPassWord';
Query OK, 0 rows affected (0.20 sec)

# 変更できたかを確認する

mysql> select user, host, plugin from mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)

# デフォルトでプラグインをよしなにするためにmy.cnfを変更しておく
# my.cnfを探す

$ mysql --help | grep my.cnf
      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

$ sudo vim /etc/my.cnf

# 以下を追記する

[mysqld]
default-authentication-plugin = mysql_native_password

# 再起動する
$ mysql.server restart

MYSQL8.0におけるデフォルトの認証プラグインの変更

my.cnfの場所を調べる

Mac での MySQL セットアップ

MySQL8.0 認証方式を変更する

3
1
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
3
1