Here's a sample code for connecting to a MySQL database using Python and an IP address:

import mysql.connector

# Connect to the database using IP address
mydb = mysql.connector.connect(
  host='192.168.0.100', # Replace with the IP address of your MySQL server
  user='yourusername',
  password='yourpassword',
  database='yourdatabase'
)

# Execute a query
mycursor = mydb.cursor()
mycursor.execute('SELECT * FROM yourtable')

# Fetch the results
result = mycursor.fetchall()
for row in result:
  print(row)

Make sure to replace the placeholder values with the actual IP address of your MySQL server, along with your username, password, database name, and table name.

Python MySQL Database Connection Using IP Address

原文地址: https://www.cveoy.top/t/topic/lEgr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录