首页 > 解决方案 > 如何用Python连接cpanel远程数据库

问题描述

我正在尝试远程访问 cpanel 数据库和记录。我使用以下代码进行sql连接,我在cpanel“ remote MySql ”中添加了“ % ”以允许任何ipaddress远程访问数据库。但我仍然收到此错误

import pymysql

    # Open database connection
    db = pymysql.connect("serverIpAddress","User","Password","DatabaseName")

    # prepare a cursor object using cursor() method
    cursor = db.cursor()

    # execute SQL query using execute() method.
    cursor.execute("SELECT VERSION()")

    # Fetch a single row using fetchone() method.
    data = cursor.fetchone()
    print ("Database version : %s " % data)

    # disconnect from server
    db.close()

我收到此错误:

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '184.164.144.130' (timed out)")

标签: pythonpython-3.xcpanelmysql-python

解决方案


推荐阅读