python database, mysql sample coding, use ip address
Here is 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.
原文地址: https://www.cveoy.top/t/topic/skE 著作权归作者所有。请勿转载和采集!