成都创新互联网站制作重庆分公司

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://cxhlcq.com/article/jgoghg.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部