[MySQL]8.x phpMyAdminでGrant文が使えない

phpMyAdminのユーザーからユーザー名を作成し、同名のデータベースを作るとエラーになります。MySQLの前のバージョンだと、これでユーザーとデータベースを同時に作成できたのですが、MySQL8からはこれができなくなったようで、エラーが出てしまいます。
CakePHP2をMySQL8環境に入れてみたらいろいろとエラーが出ました。

・phpMyAdminでユーザーを作成した時に同名のデータベースが作れない
・CakePHP2のdatabase.phpに接続情報を記載しても「SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client」とエラーがでる。

エラーの内容

phpMyAdminでのエラー
「You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘IDENTIFIED BY ‘password’ REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTION’ at line 1」

原因

GRANT文でユーザーが作成できないように変更になったようです。
phpMyAdminではGRANTを使っているのでエラーになるようです。

対策

MySQLを立ち上げます

CakePHP2

config/catabase.phpの設定を終えてファイルをアップすると、index.phpの表示で下記のようなエラーが出ます。

CakePHP is NOT able to connect to the database.

Database connection “Mysql” is missing, or could not be created.
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

こちらはMySQL8.xからユーザーの認証方式が「caching_sha2_password」になったので以前の認証方式「mysql_native_password」に変更すると直ります。

mysqlにログインします。
# mysql -u usename -p
passwordを入力

これでうまくいきます。

MySQLのデフォルトの認証形式も変更しておいたほうが良いです。

ファイルを開いたら
[mysqld]
default-authentication-plugin=mysql_native_password
を追加します。



Author: webmaster