pip install ysqlclient python import MySQLdb conn = MySQLdb.connect( host="localhost", port=3306, user="root", passwd="password", db="mydatabase" ) python cursor = conn.cursor() sql = "SELECT * FROM mytable" cursor.execute(sql) results = cursor.fetchall() for row in results: print(row) python sql = "INSERT INTO mytable (name, age) VALUES ('John', 25)" cursor.execute(sql) conn.commit() sql = "UPDATE mytable SET age = 26 WHERE name = 'John'" cursor.execute(sql) conn.commit() sql = "DELETE FROM mytable WHERE name = 'John'" cursor.execute(sql) conn.commit() python cursor.close() conn.close()


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