事象
MacでMysqlを5.6から8.0にupgradeした後、LaravelからMysqlにアクセスできなくなった。
ちなみにupgradeのコマンドは、
$ brew upgrade mysql
$ mysql_upgrade
エラー内容
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
解決方法
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
左から順に存在するファイルを確認していく
$ ll /etc/my.cnf
ls: /etc/my.cnf: No such file or directory
$ ll /etc/mysql/my.cnf
ls: /etc/my.cnf: No such file or directory
$ ll /usr/local/etc/my.cnf
-rw-r--r-- 1 hogehoge admin 167B 6 22 11:46 /usr/local/etc/my.cnf
/usr/local/etc/my.cnfが存在しているので、これの末尾に、
default_authentication_plugin= mysql_native_password
を加える
例)
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default_authentication_plugin= mysql_native_password
mysqlを再起動する
$ sudo mysql.server restart
これで完了
Tips
Sequel Proで接続できない場合は、Pre-release版からなら行けるはず
https://github.com/sequelpro/sequelpro/releases