簡體   English   中英

MariaDB不允許主機連接或拒絕用戶訪問

[英]MariaDB either not allowing host to connect or access denied for user

我有一個Laravel項目可以在本地計算機上正常運行,但是無法連接到另一台Linux服務器上的數據庫。

我得到的錯誤是:

SQLSTATE[HY000] [1045] Access denied for user 'cpanel1_thewatcher'@'localhost' (using password: YES)

這些是我正在使用的設置:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dbnamehere
DB_USERNAME=cpanel1_thewatcher
DB_PASSWORD=passwordhere

我已檢查以確保cpanel1_thewatcher在此數據庫上具有ALL PRIVILEGES ,並且密碼正確。

這是在VPS上,我具有root訪問權限,並且具有兩個專用於它的IP。 主IP我們將稱為xxx.xxx.xx.165,第二個IP為xxx.xxx.xx.166。 如果我更改上述設置以將DB_HOST設置為xxx.xxx.xx.166, DB_HOST收到其他錯誤:

SQLSTATE[HY000] [1130] Host 'xxx.xxx.xx.166' is not allowed to connect to this MariaDB server 

如果我將DB_HOST設置為xxx.xxx.xx.165,則會出現另一個錯誤:

SQLSTATE[HY000] [1045] Access denied for user 'cpanel1_thewatcher'@'server1.domain.com'

如果將DB_HOST設置為domain.com(服務器上的主域),則會收到與DB_HOST = xxx.xxx.xx.166相同的錯誤。

我檢查了服務器上的mysql.user表,發現以下內容:

+-------------------+----------------------+
| User              | Host                 |
+-------------------+----------------------+
| root              | 127.0.0.1            |
| cpanel1            | xxx.xxx.xx.165       |
| cpanel1_thewatcher | xxx.xxx.xx.165       |
| root              | ::1                  |
| cpanel1            | localhost            |
| cpanel1_thewatcher | localhost            |
| nagios            | localhost            |
| root              | localhost            |
| cpanel1            | server1.domain.com |
| cpanel1_thewatcher | server1.domain.com |
| root              | server1.domain.com |
+-------------------+----------------------+
  • 其中cpanel1是服務器上唯一的cPanel帳戶的用戶名。

我嘗試在上表中創建一個條目,其中用戶為cpanel1_thewatcher ,主機為%但沒有效果。 我還嘗試將DB_USERNAME設置為僅thewatcher但錯誤消息中沒有任何變化。

我已經看到了一些關於SO的問題,這些問題涉及到我列出的第二條錯誤消息,但是根據那里的一些答案,我無法在服務器上的任何位置找到MariaDB配置文件。

GRANT ALL PRIVILEGES ON dbnamehere.* TO 'cpanel1_thewatcher'@'localhost';

Query OK, 0 rows affected (0.00 sec)

誰能告訴我該怎么做,我對這里的2個IP和3個不同的錯誤消息感到困惑,並且不確定要嘗試什么。 我想消除一切麻煩,然后再求助於托管公司並等待一周的時間來解決問題。

您需要遵循以下步驟才能連接到遠程數據庫:

在數據庫服務器中,在mariadb控制台中運行以下命令:

CREATE USER 'cpanel1_thewatcher'@'xxx.xxx.xx.166';

其次是:

GRANT ALL PRIVILEGES ON dbnamehere.* TO 'cpanel1_thewatcher'@'xxx.xxx.xx.166';
FLUSH PRIVILEGES;

xxx.xxx.xx.166是您要連接的機器的ip laravel項目所在的laravel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM