MySQL 是一种关系型数据库管理系统,广泛用于各种应用中。在 Linux 系统上,MySQL 默认只允许本地连接。远程连接是指从另一台计算机通过网络连接到 MySQL 服务器。
原因:
my.cnf
或 my.ini
)可能限制了只允许本地连接。解决方法:
my.cnf
文件(通常位于 /etc/mysql/my.cnf
或 /etc/my.cnf
),找到并注释掉以下行:my.cnf
文件(通常位于 /etc/mysql/my.cnf
或 /etc/my.cnf
),找到并注释掉以下行:import mysql.connector
config = {
'user': 'your_username',
'password': 'your_password',
'host': 'your_server_ip',
'database': 'your_database',
'raise_on_warnings': True
}
try:
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
cursor.execute("SELECT * FROM your_table")
for row in cursor:
print(row)
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
if cnx.is_connected():
cursor.close()
cnx.close()
root
用户进行远程操作。通过以上步骤,你应该能够成功实现 MySQL 的远程连接。如果仍有问题,请检查具体的错误信息并进行相应的调试。
没有搜到相关的沙龙