Guest User

Untitled

a guest
Mar 1st, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. ############################################################
  5. # #
  6. # Simple script to connect to a remote mysql database #
  7. # #
  8. # #
  9. # Install MySQLdb package by running: #
  10. # #
  11. # pip install MySQL-python #
  12. # #
  13. ############################################################
  14.  
  15.  
  16. import MySQLdb as db
  17.  
  18. HOST = "remote host"
  19. PORT = 3306
  20. USER = "username of remote mysql instance"
  21. PASSWORD = "password of remote mysql instance"
  22. DB = "database name"
  23.  
  24. try:
  25. connection = db.Connection(host=HOST, port=PORT,
  26. user=USER, passwd=PASSWORD, db=DB)
  27.  
  28. dbhandler = connection.cursor()
  29. dbhandler.execute("SELECT * from your_table")
  30. result = dbhandler.fetchall()
  31. for item in result:
  32. print item
  33.  
  34. except Exception as e:
  35. print e
  36.  
  37. finally:
  38. connection.close()
Add Comment
Please, Sign In to add comment