要通过局域网访问别人的MySQL数据库,通常需要以下几个步骤:
原因:
解决方法:
my.cnf
或my.ini
),确保bind-address
设置为允许局域网访问的IP地址,例如:my.cnf
或my.ini
),确保bind-address
设置为允许局域网访问的IP地址,例如:原因:
解决方法:
以下是一个简单的Python示例,展示如何通过局域网连接到MySQL数据库:
import mysql.connector
config = {
'user': 'your_username',
'password': 'your_password',
'host': '192.168.1.100', # MySQL服务器的局域网IP地址
'database': 'your_database',
'port': '3306'
}
try:
connection = mysql.connector.connect(**config)
print("Connected to MySQL database!")
cursor = connection.cursor()
cursor.execute("SELECT * FROM your_table")
results = cursor.fetchall()
for row in results:
print(row)
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
if connection.is_connected():
cursor.close()
connection.close()
通过以上步骤和注意事项,你应该能够成功通过局域网访问别人的MySQL数据库。
领取专属 10元无门槛券
手把手带您无忧上云