・Windows10のXAMPP上のMariaDBのrootアカウントのパスワードを設定したい。
・phpMyAdminのログイン画面で毎回パスワードを入力する形に変更したい。
・具体的な手順を教えてほしい。
こういった疑問に答えます。
本記事の内容
- Windows10のXAMPP上のMariaDBのrootアカウントのパスワードを設定する手順
- phpMyAdminのログイン画面で毎回パスワードを入力する形に変更する手順
この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。
こういった私が、解説していきます。
私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。
Windows10のXAMPP上のMariaDBのrootアカウントのパスワードを設定する手順
手順①:XAMPPコントロールパネルからApacheとMariaDBを起動
「Apache」と「MySQL」の「Start」ボタンをクリック
手順②:コマンドプロンプトを起動してXAMPPインストールディレクトリ内へ移動
c:\xampp\mysql\bin
c:\xampp\mysql\bin>
手順③:パスワード変更コマンドを実行
mysqladmin -u root password
c:\xampp\mysql\bin>mysqladmin -u root password New password:
新しいパスワードを入力します。(確認のため再入力)
c:\xampp\mysql\bin>mysqladmin -u root password New password: ************** Confirm new password: ************** c:\xampp\mysql\bin>
手順④:新しいパスワードでMariaDBに接続テスト
mysql -h localhost -u root -p
c:\xampp\mysql\bin>mysql -h localhost -u root -p
Enter password:
新しいパスワードを入力して、接続できました。
c:\xampp\mysql\bin>mysql -h localhost -u root -p Enter password: ************** Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.4.17-MariaDB mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
接続テストが終わったら、MariaDBから切断
quit
MariaDB [(none)]> quit Bye c:\xampp\mysql\bin>
手順⑤:phpMyAdminのログイン方法の変更
rootアカウントのパスワード変更後のphpMyAdminのエラー
http://xampp.pc-ganymede.planet.space.com/phpmyadmin/
MariaDBのrootアカウントのパスワードを設定後に、
以下のようなエラーが表示されてしまい、phpMyAdminにログインすることができません。
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)
MySQL サーバに接続しようとしましたが拒否されました。config.inc.php のホスト、ユーザ名、パスワードが MySQL サーバの管理者から与えられた情報と一致するか確認してください。
phpMyAdminのログイン画面で毎回パスワードを入力する形に変更
下記ファイルをエディタで開いて編集します。
C:\xampp\phpMyAdmin\config.inc.php
19行目にあるauth_type
の値を「config」から「cookie」に変更します。
変更前
/* Authentication type and info */ $cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['AllowNoPassword'] = true; $cfg['Lang'] = '';
変更後
/* Authentication type and info */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['AllowNoPassword'] = true; $cfg['Lang'] = '';
設定変更後に再度、phpMyAdminの画面にアクセス
http://xampp.pc-ganymede.planet.space.com/phpmyadmin/
エラーが消えて、ログイン画面が表示されました。
MariaDBのrootアカウントのパスワードを入力します。
phpMyAdminにログインできました。