栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

MySQL3.python数据库增加字段

MySQL3.python数据库增加字段

#链接数据库
conn = pymysql.connect(host=‘localhost’,user=‘root’,password=‘123456’,database=‘dbmovie_top250’,port=3306,autocommit=False)
#获取游标
cursor = conn.cursor()
#执行sql
sql = “select COLUMN_NAME from INFORMATION_SCHEMA.Columns where table_name=‘t_top250’ ;”
cursor.execute(sql)
import re
sql2 = ‘alter table t_top250 drop actor2’
s = str(cursor.fetchall())
print(s)
actor = re.findall(‘actor2’,s)
print(actor)
if ‘actor2’ in actor:
cursor.execute(sql2)
print(‘actor2 is in’)
else:
print(‘actor2 is not in’)
sql1 = ‘alter table t_top250 add actor2 varchar(45);’
cursor.execute(sql1)
conn.commit()
cursor.close()
conn.close()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/280978.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号