pip install mysql-python python import MySQLdb python db = MySQLdb.connect(host="localhost", user="your_username", passwd="your_password", db="your_database") python cursor = db.cursor() sql = "SELECT * FROM tablename" cursor.execute(sql) results = cursor.fetchall() for row in results: print(row) python cursor = db.cursor() sql = "INSERT INTO tablename (column1, column2) VALUES ('value1', 'value2')" cursor.execute(sql) db.commit() python db.close()


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