Skip to content

Instantly share code, notes, and snippets.

@tao4yu
Last active August 29, 2015 14:05
Show Gist options
  • Save tao4yu/4bd465496efec871b18f to your computer and use it in GitHub Desktop.
Save tao4yu/4bd465496efec871b18f to your computer and use it in GitHub Desktop.
python 连接mysq
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import sys
def mysqlFunc():
try:
conn = MySQLdb.connect(host = 'localhost', port = 3306, user = 'root', passwd = '123456', db = 'dbname')
cur = conn.cursor()
cur.execute("")
conn.commit()
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
if __name__ == '__main__':
mysqlFunc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment