安裝完 XAMPP 開啟控制面板,啟動 Apache & MySQL 而在 MySQL 的同列有一個 Admin 按鈕,這就是開啟 phpMyAdmin 的方式,這是一件再平常不過的事,但今天在另一台電腦裝完 XAMP 後開啟 phpMyAdmin 後發生資料庫連線錯誤
錯誤訊息
MySQL said: Cannot connect: invalid settings.
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)
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.
著手解決
依照經驗這是密碼錯誤造成的,如果你是預設安裝路徑,你可以直接用文字編輯器開啟下方這個檔案
C:\Xampp\phpMyAdmin\config.inc.php
這是 phpMyAdmin 的設定檔,在檔案中找到下面這幾行
/* 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'] = false;
$cfg['Lang'] = '';
發現密碼是沒有被設定的,我們在 $cfg['Servers'][$i]['password']
中鍵入我們要的密碼,並且把 $cfg['Servers'][$i]['AllowNoPassword']
改為 false,像下方這樣
$cfg['Servers'][$i]['password'] = '123';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
接著儲存檔案,重啟 MySQL,重新進入 phpMyAdmin,賓果!! 看到登入畫面了,登入成功