# coding:utf-8 # python2 import pymysql db = pymysql.connect( host='127.0.0.1', db='数据库', user='用户', passwd='数据库密码', charset='utf8', use_unicode=True) cursor = db.cursor() #要删除的表 del_table = ['auth_user_groups', 'auth_group_permissions', 'auth_group', 'auth_user_user_permissions', 'auth_permission', 'django_admin_log', 'auth_user', 'djcelery_periodictasks', 'djcelery_periodictask', 'djcelery_crontabschedule', 'djcelery_intervalschedule', 'djcelery_taskstate', 'djcelery_workerstate'] for i in del_table: sql = "DROP TABLE IF EXISTS {}".format(i) try: cursor.execute(sql) print 'table:{}--已被删除'.format(i) except Exception as e: print e