Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pip install mysqlclient
- import MySQLdb as db
- HOST = "remote host"
- PORT = 3306
- USER = "username of remote mysql instance"
- PASSWORD = "password of remote mysql instance"
- DB = "database name"
- try:
- connection = db.Connection(host=HOST, port=PORT,
- user=USER, passwd=PASSWORD, db=DB)
- dbhandler = connection.cursor()
- dbhandler.execute("SELECT * from your_table")
- result = dbhandler.fetchall()
- for item in result:
- print item
- except Exception as e:
- print e
- finally:
- connection.close()
Add Comment
Please, Sign In to add comment