forked from smilejay/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqldb-python2.py
More file actions
28 lines (24 loc) · 543 Bytes
/
mysqldb-python2.py
File metadata and controls
28 lines (24 loc) · 543 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python2.7
# coding=utf-8
import MySQLdb
import sys
host = 'localhost'
user = 'root'
pwd = '123456' # to be modified.
db = 'test'
if __name__ == '__main__':
conn = MySQLdb.connect(host, user, pwd, db, charset='utf8');
try:
conn.ping()
except:
print 'failed to connect MySQL.'
sql = 'select * from mytable where id = 2'
cur = conn.cursor()
cur.execute(sql)
row = cur.fetchone()
# print type(row)
for i in row:
print i
cur.close()
conn.close()
sys.exit()