LoginSignup
1
0

【XAMPP】phpMyAdminに接続できない場合の対処法

Last updated at Posted at 2023-12-03

XAMPPのコントロールパネルから、phpMyAdminに接続できなかった時に試したことをまとめています。
結論から言うと、phpMyAdminの設定ファイル (config.inc.php) を諸々いじる必要があります。
特に、MySQLに特定のポート番号を割り当てている場合は、特別な設定が必要でした。

困っていたこと

XAMPPのコントロールパネルから、phpMyAdminに接続しようとすると以下のようなエラーが出る。
スクリーンショット 2023-12-04 015346.png

動作環境

  • Windows 11 Home
  • XAMPP for Windows 8.2.12
    • Apache/2.4.58 (Win64)
    • PHP 8.2.12
    • 10.4.32-MariaDB

エラー発生までの前提

試したこと

1. phpMyAdminの設定ファイルに管理者アカウント(root)のパスワードを記載

phpMyAdminの設定ファイル (C:\xampp\phpMyAdmin\config.inc.php) に、管理者アカウント(root)のパスワードを記載する必要があるみたいだったので、追加しました。

<変更前>

C:\xampp\phpMyAdmin\config.inc.php
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';

<変更後>

C:\xampp\phpMyAdmin\config.inc.php
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '********';

(参照URL : https://www.javadrive.jp/xampp/mysql/index3.html)

<結果>
ページ最初の画像と変わらず、エラーが出る。。。

2. phpMyAdminの設定ファイルにMySQLのポート番号を追加

https://teratail.com/questions/29659
にて、質問をしている方が自分と同じ部分で詰まっていたので、詳しく読んでみることに。
すると、自分のphpMyAdminの設定ファイルには、ポート番号情報がないことに気づく。(どうやらデフォルトでの記載はない模様)
試しに、上の記事を参考にして自分の設定ファイルにもポート番号情報を書き込む。

<変更前>

C:\xampp\phpMyAdmin\config.inc.php
/*
 * First server
 */
$i++;

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';

<変更後>

C:\xampp\phpMyAdmin\config.inc.php
/*
 * First server
 */
$i++;

$cfg['Servers'][$i]['port'] = '1234';

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';

<結果>
見事、アクセスできました!!
スクリーンショット 2023-12-04 024600.png

原因

XAMPPインストール時、ポートの競合により、MySQLが起動できない状態でした。
そのため、MySQLのポートを'3306'から'1234'に変更しており、おそらくこれが原因だったと思われます。
(参照URL : https://qiita.com/nananari/items/66df067499a0e80e1036)

余談

MySQLに特定のポート番号の割り当てを行っている場合には、PHPにてPDOを用いたMySQL接続を行う際にも特別な設定が必要です。
具体的には、データソース名($dsn)に、ポート番号の情報を加える必要があります。

db_connect.php
$dsn = 'mysql:dbname=mysql;host=localhost;port=1234';
$user = 'root';
$password = '********';

$pdo = new PDO($dsn, $user, $password);

(参照URL : https://blog.diginnovation.com/archives/7143/)

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