3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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におけるデフォルトの認証プラグインの変更]
(http://variable.jp/2018/02/23/mysql8-0%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%81%AE%E8%AA%8D%E8%A8%BC%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%AE%E5%A4%89%E6%9B%B4/)

[my.cnfの場所を調べる]
(https://qiita.com/is0me/items/12629e3602ebb27c26a4)

[Mac での MySQL セットアップ]
(https://qiita.com/itooww/items/13055c8bb1d226ee5844)

[MySQL8.0 認証方式を変更する]
(https://qiita.com/ucan-lab/items/3ae911b7e13287a5b917)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?