
Error establishing a database connection
最近搞了一下網(wǎng)站遷移,因?yàn)橹鲝耐接袉栴}就又重新遷移回去了,結(jié)果解決同步的時候不清楚咋把另一個網(wǎng)站的數(shù)據(jù)庫連接給干出Error了。Error如圖所示(Error establishing a database connection)
確定密碼是否正確
進(jìn)網(wǎng)站目錄查看
wp-config.php的數(shù)據(jù)庫信息。用數(shù)據(jù)庫登錄信息測試密碼
mysql -uUsername -p
- 如能成功登錄則去核查相關(guān)表的權(quán)限是否存在,不能則切root用戶更改密碼。
# 我這里是5.7的版本
update mysql.user set authentication_string=password('passwd') where user='Username' and Host = 'localhost';
# 刷新權(quán)限
flush privileges;
- 如果root也切換不了,就改數(shù)據(jù)庫配置,主要是在mysql配置文件中的
[mysqld]加入如下內(nèi)容即可。
#繞過密碼驗(yàn)證
skip-grant-tables
- 如果不行,嘗試數(shù)據(jù)庫重啟一下
核查權(quán)限
- 切表是否能切過去
use dbName;

- 不能則切換root用戶賦予相關(guān)權(quán)限
mysql -uroot -p
grant all privileges on `database_name`.* to 'user_name'@'hostname';

修復(fù)數(shù)據(jù)庫
如需了解更多,請?jiān)L問: https://www.emperinter.info/2022/05/06/error-establishing-a-database-connection/