1
2
3
4
5
6
7
8
9
10
11
12
13
|
# -*- coding: utf-8 -*- import MySQLdb
try :
conn = MySQLdb.connect(host = 'localhost' ,user = 'root' ,passwd = '123456' ,db = 'python_test' ,port = 3306 )
cur = conn.cursor() #光标
cur.execute( 'use python_test;' )
cur.execute( 'CREATE TABLE test(id char(20));' )
cur.close()
conn.close()
except MySQLdb.Error,e:
print '连接失败。' ,e
|
安装MySQLdb模块:
yum install MySQL-python -y
本文转自 天道酬勤VIP 51CTO博客,原文链接:http://blog.51cto.com/tdcqvip/1954100