简体   繁体   中英

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?

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.
  2. Ask your host if port 3306 is open.

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.
  2. Use your server's hostname or IP as the MySQL Host in your connection configuration.

And if you still cannot establish a successful connection, I recommend switching to a managed hosting provider that fully supports remote MySQL connections. You can check for a suitable one here: https://hostadvice.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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