Guest User

Untitled

a guest
May 11th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. # pip install mysqlclient
  2.  
  3. import MySQLdb as db
  4.  
  5. HOST = "remote host"
  6. PORT = 3306
  7. USER = "username of remote mysql instance"
  8. PASSWORD = "password of remote mysql instance"
  9. DB = "database name"
  10.  
  11. try:
  12. connection = db.Connection(host=HOST, port=PORT,
  13. user=USER, passwd=PASSWORD, db=DB)
  14.  
  15. dbhandler = connection.cursor()
  16. dbhandler.execute("SELECT * from your_table")
  17. result = dbhandler.fetchall()
  18. for item in result:
  19. print item
  20.  
  21. except Exception as e:
  22. print e
  23.  
  24. finally:
  25. connection.close()
Add Comment
Please, Sign In to add comment