LoginSignup
18
11

More than 3 years have passed since last update.

phpMyadmin 接続できない 

Last updated at Posted at 2020-03-30

はじめに

phpを学習していくうちに、mysqlのバージョンをUPDATEした際に起こったエラーです。
php、mysql学習中であり、かなりてこずったので備忘ログとして残しておく。

私のmacOSデバイスでは、ローカルのWeb開発にMAMPアプリを使用しています。しかし、phpMyAdmin Webページにアクセスしようとすると、次のエラーメッセージが表示から始まりました。

エラー内容

スクリーンショット 2020-03-29 21.56.27.png

今まではphpMyadminに接続できていたのに、急にこの画面のエラーが...

エラー内容はこんな感じです。

1.接続できません:無効な設定

Cannot connect: invalid settings

2.'localhost'のアクセスが拒否されました(パスワードを使用:YES)

mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)

3.構成内のホスト、ユーザー名、パスワードを確認し、それらがMySQLサーバーの管理者から提供された情報に対応していることを確認してください。

phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

解決策

この問題を解決するには、phpMyAdmin構成ファイルを変更して、MySQL rootユーザーの実際のパスワードを使用するだけ。
ただこれだけでよったのです...

phpMyAdmin構成ファイル設定

1.MAMPアプリが実行されている場合は、Stop Serversボタンをクリックしてアプリを終了します。

2.Finderで、フォルダに移動Applications→ MAMP→ bin→ phpMyAdmin。

3.config.inc.phpテキストエディターでファイルを開きます。

4.検索を使用して、以下の行を見つけます(大体87行目あたり)

$cfg['Servers'][$i]['auth_type']     = 'config';    // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user']          = 'root';     // MySQL user

*'root'MySQLのrootユーザーの実際のパスワードに置き換えます。
$cfg['Servers'][$i]['password']      = 'root';     // MySQL password (

これでphpMyAdmin構成ファイル設定はおk!

MySQL rootユーザの設定

実際、rootユーザのパスワード等を忘れてしまった方(Mysql8の場合)はこちら参考に
https://qiita.com/avicii2314/items/3a6c9da5f9195c93be9a

(補足) MySQL8のパスワード認証プラグインについて

MySQLでは、パスワードの認証時に、実行される、「authentication plugin」という仕組みのがあります。

例えば上記のコマンドで設定したパスワードについて、下記のコマンドで、確認できます。

mysql> select User, Plugin from mysql.user where User = 'root';
+------+-----------------------+
| User | Plugin                |
+------+-----------------------+
| root | caching_sha2_password |
+------+-----------------------+Copy

下のコマンドで確かめられるように、MySQL8 からは、「caching_sha2_password」がデフォルトとなったようなのですが・・、

mysql > use mysql;
mysql > show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+Copy

mysqlを利用するクライアントソフトウェア(例えば、PhpMyAdminなど)では、この認証方法をサポートしていないため、エラーとなりログイン出来ないことがあるみたいです。

パスワードを下記のコマンドで設定すると、回避できます。

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

MAMP(pro)設定確認

ここ
cahnge password of user"root":

パスワードをしっかり合わせる
スクリーンショット 2020-03-30 12.00.57.png

phpMyAdmin Webページにアクセス

https://localhost/phpMyAdmin/index.php
アクセスできれば完了です。

最後に

このエラーを通じて、mysqlの設定や、phpMyadminの設定方法が少しですが、身につきました。
この記事が問題の解決に役に立てれば幸いです。

参考サイト
https://mycyberuniverse.com/phpmyadmin-fails-access-mysql.html

認証プラグインについて
https://www.s-style.co.jp/blog/2018/05/1807/

18
11
1

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
18
11