python连接数据库
# -*- 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
我们提供的服务有:成都网站设计、成都做网站、微信公众号开发、网站优化、网站认证、揭东ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的揭东网站制作公司
安装MySQLdb模块:
yum install MySQL-python -y
当前标题:python连接数据库
浏览路径:http://www.jxjierui.cn/article/jgoghg.html


咨询
建站咨询
