fork download
  1. import mysql.connector
  2. mycon = mysql.connector.connect(
  3. host='localhost',
  4. user='root',
  5. password='password',
  6. database='School')
  7. if mycon.is_connected():
  8. print('Database connected')
  9. cursor = mycon.cursor()
  10. sql ="SELECT * FROM STUDENT ORDER BY Name"
  11. cursor.execute(sql)
  12. data = cursor.fetchall()
  13. print("Answer is:")
  14. for rec in data:
  15. print(rec)
  16. sql ="DELETE FROM STUDENT WHERE ID = 3"
  17. cursor.execute(sql)
  18. mycon.commit()
  19. mycon.close()
Success #stdin #stdout 0.04s 25720KB
stdin
Standard input is empty
stdout
import mysql.connector
mycon = mysql.connector.connect(
     host='localhost', 
     user='root',
     password='password',
     database='School')
if mycon.is_connected():
   print('Database connected')
cursor = mycon.cursor()
sql ="SELECT * FROM STUDENT ORDER BY Name"
cursor.execute(sql)
data = cursor.fetchall()
print("Answer is:")
for rec in data:
    print(rec)
sql ="DELETE FROM STUDENT WHERE ID = 3"
cursor.execute(sql)
mycon.commit()
mycon.close()