[英]Fix Access denied for user 'root'@'localhost' for phpMyAdmin
我在 PC 上使用 WAMP Server 2.2。 在 phpMyAdmin(版本 5.5.24)中,我編輯了“root”用戶(使用“localhost”主機)並給它一個密碼“root”。 結果證明這是一個我試圖恢復的大錯誤。 現在,當我轉到localhost/phpmyadmin/ 時,我會看到左側的數據庫菜單,但是主框架有一個錯誤,內容如下:
#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.
如果我轉到127.0.0.1/phpmyadmin ,我不會收到錯誤並且一切正常。
我嘗試將用戶的密碼改回無密碼; 我嘗試修改 config.inc.php 文件以添加新密碼(但這使 phpMyAdmin 完全出錯); 我嘗試刪除並重新創建 root/localhost 用戶。 似乎沒有任何效果。 root/localhost 用戶似乎沒有密碼和所有權限,但錯誤仍然存在。
有什么想法或如何使該用戶的訪問恢復正常而無需重新安裝 WAMP?
在C:\\wamp\\apps\\phpmyadmin3.5.1
下找到config.inc
文件在這個文件里面找到這一行
$cfg['Servers'][$i]['password'] =";
並將其替換為
$cfg['Servers'][$i]['password'] = 'Type your root password here';
我有同樣的問題我已經在數據庫中更改密碼后..我所做的就是前面我已經改變了更新密碼的編輯,我並沒有在config.inc.php文件和d在相同的用戶名更新: \\xamp\\phpMyAdmin\\config.inc
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = **'root'**;
$cfg['Servers'][$i]['password'] = **'epufhy**';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';
在 phpMyAdmin 頁面中更改“root”的密碼后,我遇到了同樣的問題,也在互聯網上尋找解決方案,但沒有得到我需要的答案,所以我查看了 phpMyAdmin 目錄中的文檔。
轉到並編輯文件
\modules\phpmyadmin414x140123114237\config.sample.inc.php
找線
$cfg['Servers'][$i]['auth_type'] = 'config'
並將“配置”更改為“http” ,這將允許您在使用瀏覽器訪問 phpMyAdmin 頁面時輸入用戶名和密碼。
或
查看同一 phpMyAdmin 目錄下的文檔文件 ( phpmyadmin414x140123114237\\doc\\html
) 尋求幫助並搜索$cfg['Servers'][$i]['auth_type']
,您將看到 4 個選項可供選擇,以了解如何登錄到您的 phpMyAdmin 頁面。
在 C:\\xampp\\phpMyAdmin 下找到 config.inc.php 文件並在任何編輯器中打開它。 找到以下行:
$cfg['Servers'][$i]['password'] = ' ';
在引號內輸入選擇的密碼。 此外,為了讓 localhost/phpmyadmin 要求輸入用戶名和密碼,請找到以下行:
$cfg['Servers'][$i]['auth_type'] = 'config';
將上面的行更改為:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
如果您有 mysql 的現有密碼,請按如下所述寫:
在C:\\wamp\\apps\\phpmyadmin3.5.1下找到 config(dot)inc 文件在這個文件里面找到這一行
$cfg['Servers'][$i]['password'] =";
並將其替換為
$cfg['Servers'][$i]['password'] = **'your-password'**;
嗯..這對我來說似乎很奇怪,但它突然起作用了!!
我所做的正是:
突然它起作用了!
@Dagon 有正確的想法,但在細節上有點欠缺。
如果您使用訪問127.0.0.1/phpmyadmin
並仔細查看在 MySQL 中設置的用戶,您應該會看到 3 個版本的root
用戶名。
這是因為在 MySQL 中,每個用戶 ID 都與一個 HOST 相關聯,即允許用戶登錄的 PC(IP 地址)。 因此,您的 3 個“root”用戶 ID 實際上是允許從 3 個單獨的主機登錄的相同用戶 ID。 通常開箱即用的“root”有 3 個 HOSTS 設置,127.0.0.1、localhost 和 ::1
這些是:-
localhost 是從您的 HOSTS 文件( c:\\windows\\system32\\drivers\\etc\\hosts )創建的此機器的別名
127.0.0.1 是這台機器的 IPv4 環回 IP 地址
::1 是這台機器的 IPv6 環回 IP 地址
您可能遇到的情況是您為 root@127.0.0.1 設置了密碼,但沒有為其他任何密碼設置密碼。 現在您的瀏覽器將“任意”決定使用 ::1 或 127.0.0.1 作為主機 IP,因此當它使用 ::1 時,您的登錄將失敗。
因此,使用127.0.0.1/phpmyadmin
登錄並將所有 3 個“root”用戶名更改為具有相同的密碼,您應該不會再看到此問題。
還要確保您的 HOSTS 文件有這 2 個條目
127.0.0.1 localhost
::1 localhost
要解決上述錯誤:-
a) Open Mysql console from the tray of WAMP server
b) It will ask for a password(you might have set this password earlier when u installed MySql in your system)(In my case it is admin)
c) Enter admin (press enter)
現在這意味着您的 PhpMyAdmin 假設您的 MySql 沒有密碼並且無法連接 MySql,但是您可以通過提供密碼來連接您的 MySql 服務器,此打開 config.inc 文件來自以下路徑
C:\\wamp\\apps\\phpmyadmin4.1.14
並替換這一行
$cfg['Servers'][$i]['password'] =' ';
到
$cfg['Servers'][$i]['password'] = 'admin';
我希望它會起作用...
使用$cfg['Servers'][$i]['auth_type'] = 'config';
我認為是不安全的。
在$cfg['Servers'][$i]['auth_type'] = 'cookie';
我認為更好。
我還補充道:
$cfg['LoginCookieRecall'] = true;
$cfg['LoginCookieValidity'] = 100440;
$cfg['LoginCookieStore'] = 0; //Define how long login cookie should be stored in browser. Default 0 means that it will be kept for existing session. This is recommended for not trusted environments.
$cfg['LoginCookieDeleteAll'] = true; //If enabled (default), logout deletes cookies for all servers, otherwise only for current one. Setting this to false makes it easy to forget to log out from other server, when you are using more of them.
我在phi.ini中添加了這個
session.gc_maxlifetime=150000
什么對我有用:
轉到 config.inc.php。
改變
$cfg['Servers'][$i]['AllowNoPassword'] = true;
到
$cfg['Servers'][$i]['AllowNoPassword'] = false;
改變
$cfg['Servers'][$i]['password'] = '';
到
$cfg['Servers'][$i]['password'] = ' ';
改變
$cfg['Servers'][$i]['auth_type'] = 'config';
到
$cfg['Servers'][$i]['auth_type'] = 'http';
重新加載頁面 http://localhost/phpmyadmin
類型:根
通過:(空)
現在您可以訪問它。 :)
我使用此 URL 輸入 phpMyAdmin http://localhost:2145/phpmyadmin但收到以下錯誤:
“phpMyAdmin 嘗試連接 MySQL 服務器,服務器拒絕連接。您應該檢查配置中的主機、用戶名和密碼,並確保它們與 MySQL 服務器管理員提供的信息相對應”
我的 config.inc.php 文件是
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['host'] = 'localhost:2145';
$cfg['Servers'][$i]['connect_type'] = 'cookie';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
此更改為我解決了錯誤
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
然后
sudo service mysql stop
/opt/lampp/lampp start
並解決了問題
xampp\\phpMyAdmin/config.inc
查找-
$cfg['Servers'][$i]['auth_type'] = 'config'
並將“配置”更改為“http”,這將允許您在使用瀏覽器訪問 phpMyAdmin 頁面時輸入用戶名和密碼。
還要注意“setup”(即localhost/phpmyadmin/setup)在處理“無密碼”選項的方式上有錯誤。 雖然它創建了一行,上面寫着:
$cfg['Servers'][$i]['nopassword'] = true;
參數的實際名稱應如下所示:
$cfg['Servers'][$i]['AllowNoPassword'] = true;
截至 2015 年 10 月 20 日,此“設置”錯誤仍存在。
嘗試找到 $cfg['Servers'][$i]['password'] = ''; 在位於 wamp/scripts/config.inc.php 的配置文件中
然后將密碼設置為你的mysql密碼並刷新PhpmyAdmin
我也遇到了這個問題
我發現 phpmyadmin 的配置文件中的密碼字段為空。 我把我填入數據庫設置的密碼。 現在它工作正常
我在使用 XAMPP 和 phpMyAdmin 時遇到了同樣的問題,這就是我輕松解決的方法。
有時配置並不總是問題所在。
嘗試檢查 MySql 配置。 如果你改變了端口號。 在 mysql 上對 PHP 配置php.ini
進行類似的更改。 查找並替換必要的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.