1. 程式人生 > >新手PHP連接MySQL數據庫出問題(Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES))

新手PHP連接MySQL數據庫出問題(Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES))

admin 提示 文件 無法 sin for serve 方法 onf

我用的環境是wampServer集成的軟件包

在php連接MySQL數據庫的時候老是出現這個問題
Warning: mysqli_connect(): (HY000/1045): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

你好,我也遇到過這個問題,下面是我的解決方法:

首先,通過WAMP打開mysql控制臺。

提示輸入密碼,因為現在是空,所以直接按回車。(wamp 默認數據庫密碼為空)

然後輸入“use mysql”,意思是使用mysql這個數據庫,提示“Database changed”就行。

然後輸入要修改的密碼的sql語句

“ update user set password=PASSWORD(‘hooray‘) where user=‘root‘; ”

最後輸入“flush privileges;”
,不輸入這個的話,修改密碼的操作不會生效的。

然後輸入“quit”退出。

現在MYSQL已經加上密碼了,
這時候通過wampserver訪問phpmyadmin會發現無法訪問,沒有權限,需要輸入密碼,
這時間就需要改動wamp安裝目錄裏的 config.inc.php文件了!

打開config.inc.php文件,
找到如下位置:

$cfg[‘Servers‘][$i][‘user‘] = ‘root‘;

在password對應的後面寫上之前設置的密碼
,然後就可以登錄phpmyadmin了!(*^__^*) 嘻嘻……

新手PHP連接MySQL數據庫出問題(Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES))