标签:python mysql
# -*- 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
本文出自 “天道酬勤” 博客,请务必保留此出处http://tdcqvip.blog.51cto.com/12995943/1954100
标签:python mysql
原文地址:http://tdcqvip.blog.51cto.com/12995943/1954100