scrapy连接myqsl

在pipeline中:

def __init__(self):
    self.connect = pymysql.connect(
        host='localhost',
        port=3306,
        db='****',
        user='root',
        passwd='****',
        charset='utf8')
    self.cursor = self.connect.cursor()
self.cursor.execute(
    '''insert into tablename(t, d, p)
    values (%s, %s, %s);''',
self.connect.commit()

连接数据库用pymysql

操作数据库的增删改查的时候不要忘记“;”

删除列:alter table tablename drop column 列名;

增加列:alter table tablename add   column 列名 (类型);

查询表的结构:desc tablename;


猜你喜欢

转载自blog.csdn.net/z13405546523/article/details/80213995
今日推荐