从mysqldump创建表(如果不存在) [英] Create table if not exists from mysqldump

查看:550
本文介绍了从mysqldump创建表(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道mysqldump中是否有任何方法可以添加适当的创建表选项[IF NOT EXISTS].有什么想法吗?

I'm wondering if there is any way in mysqldump to add the appropriate create table option [IF NOT EXISTS]. Any ideas?

推荐答案

根据一个来源,mysqldump没有此选项.

According to one source, mysqldump does not feature this option.

您可以在导入转储文件时使用--force选项,其中MySQL将忽略尝试创建重复表而产生的错误.但是请注意,使用这种方法,其他错误也将被忽略.

You could use the --force option when importing the dump file back, where MySQL will ignore the errors generated from attempts to create duplicate tables. However note that with this method, other errors would be ignored as well.

否则,您可以通过脚本运行转储文件,该脚本将用CREATE TABLE IF NOT EXISTS替换所有出现的CREATE TABLE.

Otherwise, you can run your dump file through a script that would replace all occurrences of CREATE TABLE with CREATE TABLE IF NOT EXISTS.

这篇关于从mysqldump创建表(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆