简体   繁体   English

无法使用 python 远程连接到 cpanel 中的 mysql 数据库

[英]can't remotely connect to mysql database in cpanel with python

I tried to connect remotely to my database in cpanel in all ways but it won't let me, does anyone know why it doesn't give me access?我尝试以各种方式远程连接到我在 cpanel 中的数据库,但它不会让我,有谁知道为什么它不给我访问权限?

HOST = "xxxxxxxxx"
DATABASE = "xxxxxxxxx"
USER = "xxxxxxxxxxx"
PASSWORD = "xxxxxxx"

db_connection = mysql.connect(host=HOST, database=DATABASE, user=USER, password=PASSWORD)
print("Connected to:", db_connection.get_server_info())


#####################################################################################

python3 sqlConect.py 
Traceback (most recent call last):
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/network.py", line 509, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:在处理上述异常的过程中,又出现了一个异常:

Traceback (most recent call last):
  File "/home/miguel/Desktop/python/sqlConect.py", line 61, in <module>
    db_connection = mysql.connect(host=HOST, database=DATABASE, user=USER, password=PASSWORD)
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/abstracts.py", line 716, in connect
    self._open_connection()
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 206, in _open_connection
    self._socket.open_connection()
  File "/home/miguel/.local/lib/python3.10/site-packages/mysql/connector/network.py", line 511, in open_connection
    raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'industriasbjt.com:3306' (111 Connection refused)

在cpanel中,当您尝试远程连接并且端口3306拒绝访问时,您必须联系cpanel提供商并检查提供远程访问的计划,因为如果端口3306被阻止,远程连接计划可能会受到限制,这只是一个问题与提供 cpanel 的提供商交谈

I would suggest:我会建议:

  1. Ask your hosting provider if they ALLOW remote MySQL connections.询问您的托管服务提供商是否允许远程 MySQL 连接。
  2. Ask your host if port 3306 is open.询问您的主机端口 3306 是否打开。

If the above is covered, then you will need to:如果上述内容已涵盖,那么您将需要:

  1. Add the IP address of the remote machine ( where you are trying to establish this connection ) to "Remote MySQL" in cPanel.将远程计算机的 IP 地址(您尝试建立此连接的位置)添加到 cPanel 中的“远程 MySQL”。
  2. Use your server's hostname or IP as the MySQL Host in your connection configuration.在连接配置中使用服务器的主机名或 IP 作为 MySQL 主机。

And if you still cannot establish a successful connection, I recommend switching to a managed hosting provider that fully supports remote MySQL connections.如果仍然无法建立成功的连接,我建议切换到完全支持远程 MySQL 连接的托管主机提供商。 You can check for a suitable one here: https://hostadvice.com/您可以在这里查看合适的: https ://hostadvice.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM