Last active
August 29, 2015 14:05
-
-
Save tao4yu/4bd465496efec871b18f to your computer and use it in GitHub Desktop.
python 连接mysq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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