135-1821-9792

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连接数据库
网站URL:http://kswsj.com/article/jgoghg.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号