perloader

按照某个键值将最小ID创建新表储存:

create table tmp_table as select min(id) from wp_posts group by post_title;

然后将储存在tmp中的id与原表对照,将原表中不存在与tmp中的id删除:

delete from wp_posts where id not in (select * from tmp_table);

py脚本

squ=["create table tmp_table as SELECT ID FROM `wp_posts` WHERE `post_name` REGEXP '-2$';","delete from wp_posts where id in (select * from tmp_table);","DROP TABLE tmp_table;"]
for sqa in squ:
    try:
        db = MySQLdb.connect(host='xxx.xxx.xxx.xxx', user='root', passwd='xxxxxx', db='xxxx', port=3306,
                             charset='utf8', cursorclass=MySQLdb.cursors.DictCursor)
        cursor = db.cursor()
        cursor.execute(sqa)
        db.commit()
        db.close()
    except:
        print('error db')

删除包含xxx关键字的所有文章

create table tmp_table as SELECT id FROM `wp_posts` WHERE `post_content` REGEXP 'xxx';
delete from wp_posts where id in (select * from tmp_table);

 

xyz