导出mysql时如何删除索引和触发器?

wsxa1bj1  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(315)

大家好,
使用mysqldump,我导出数据库的模式和数据。
这是我的密码:

self.BACKUP_PATH = 'SqlBackup'
self.FILE_NAME_SCHEMA = self.BACKUP_PATH + '/tribot_schema_pack.sql'
self.FILE_NAME_DATA_PACK = self.BACKUP_PATH + '/tribot_data_pack.sql'

self.MYSQL_SETTINGS = '-h ' + self.DB_HOST + ' -u ' + self.DB_USER + ' --password=' + self.DB_USER_PASSWORD
self.DUMP_CODE = self.MYSQL_DUMP_DIR + '/mysqldump ' + self.MYSQL_SETTINGS
self.DUMP_MYSQL_CODE = self.MYSQL_DUMP_DIR + '/mysql ' + self.MYSQL_SETTINGS

command_schema = '%s --no-data --skip-triggers %s > %s' % \
                 (self.DUMP_CODE, self.DB_NAME, pipes.quote(self.FILE_NAME_SCHEMA))

command_data = '%s --no-create-info %s > %s' % \
               (self.DUMP_CODE, self.DB_NAME, pipes.quote(self.FILE_NAME_DATA_PACK))

subprocess.Popen(command_schema, shell=True).wait()

subprocess.Popen(command_data, shell=True).wait()

如何在导出时不导入索引和触发器?

zkure5ic

zkure5ic1#

command_schema = '%s --no-data --skip-triggers --disable-keys %s > %s' % \
                 (self.DUMP_CODE, self.DB_NAME, pipes.quote(self.FILE_NAME_SCHEMA))

command_data = '%s --no-create-info --skip-triggers --disable-keys %s > %s' % \
               "`ALTER TABLE tribot_place_raw_placetags DROP FOREIGN KEY tribot_place_raw_placetags_citynames;`"
    "`ALTER TABLE ``tribot_place_raw_placetags`` DROP INDEX ``tribot_place_raw_placetags_citynames``;`"

我没有得到这样的触发器:——跳过触发器
对于键我,不幸的是,去掉了我出现在样本上的键;

"`ALTER TABLE tribot_place_raw_placetags DROP FOREIGN KEY tribot_place_raw_placetags_citynames;`"

"`ALTER TABLE ``tribot_place_raw_placetags`` DROP INDEX ``tribot_place_raw_placetags_citynames``;`"

相关问题