bash pip install PyMySQL python import pymysql conn = pymysql.connect( host='localhost', user='username', password='password', database='database_name' ) cursor = conn.cursor() cursor.execute("SELECT * FROM table_name") result = cursor.fetchall() print(result) conn.close() python cursor.execute("SELECT * FROM table_name") result = cursor.fetchall() print(result) python cursor.execute("INSERT INTO table_name (column1, column2) VALUES (%s, %s)", ("value1", "value2")) conn.commit() python try: cursor.execute("SELECT * FROM table_name") result = cursor.fetchall() print(result) except pymysql.Error as e: print("Error:", e)


上一篇:
下一篇:
切换中文