[英]Codeigniter app in shared hosting can't connect to remote mysql in vps
[英]Can't connect with remote user to MySQL (hosted on Ubuntu VPS)
我正在嘗試為我的MySQL數據庫設置一個遠程用戶,以便可以從任何IP訪問它。 MySQL服務器托管在Ubuntu VPS服務器上。
您已經在這里看到了,我已經創建了一個遠程用戶:
login as: root
root@xx.xx.xx's password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-108-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
82 packages can be updated.
42 updates are security updates.
Last login: Fri Mar 2 19:47:15 2018 from xxxxxxx
root@vpsxxxxxx:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW variables WHERE Variable_name = 'hostname' OR Variable_name = 'port';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| hostname | vps520749 |
| port | 3306 |
+---------------+-----------+
2 rows in set (0.01 sec)
mysql> SELECT Host,User from mysql.user;
+-----------+------------------+
| Host | User |
+-----------+------------------+
| % | user |
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)
mysql>
但是一旦我嘗試通過Navicat或MySQL Workbench用用戶user
登錄,就會收到此錯誤:
即使我嘗試通過SSH連接到SQL Server,我仍然會收到錯誤消息:
在這里我的連接設置:
我在這里想念什么?
也許防火牆設置不允許訪問端口3306? 您可以通過使用實用程序(例如netcat(nc))連接到端口,從命令提示符處檢查它是網絡問題還是應用程序問題。
例如,從運行Navicat / MySQLWorkbench的計算機連接到地址為192.168.0.100的數據庫服務器:
user@server1:~> nc -zvn 192.168.0.100 3306
nc: connect to 192.168.0.100 port 3306 (tcp) failed: Connection refused
user@server1:~>
-----
user@server1:~> nc -zvn 192.168.0.100 3306
Connection to 192.168.0.100 3306 port [tcp/*] succeeded!
user@server1:~>
要通過服務器的主機名進行連接,請省略-n選項:
您可能對遠程特權有問題。 如果是這種情況,請在命令行上打開MySQL,然后在以下命令中輸入:
GRANT ALL PRIVILEGES
ON my_database_name.*
TO 'user'@'%'
IDENTIFIED BY 'new_remote_password';
FLUSH PRIVILEGES;
'%'是通配符,因此TO
行表示具有任何IP地址的用戶名'user'可以訪問。 但他們需要密碼new_remote_password
。 如您所見, ON
行將這種訪問限制為對一個數據庫my_database_name的訪問。
這樣做有一些明顯的安全隱患,因此請確保您知道這方面的工作。
以下是一些其他可能的修復:
在配置文件中更改一兩行。 通常,配置文件位於Ubuntu上的/etc/mysql/my.cnf
或/etc/mysql/mysql.conf.d/mysqld.cnf
上。 擺脫或注釋掉那些說
bind-address = 127.0.0.1
和
skip-networking
您也將需要使用命令行中的sudo service mysql restart
來重新啟動MySQL。
如果這些都不起作用,則可能是防火牆或端口問題,如另一個答案所建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.