如何使用触发器和程序导出 MySQL 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5075198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to export MySQL database with triggers and procedures?
提问by Yugal
How to export/dump mysql database with all triggers and procedures.
如何使用所有触发器和过程导出/转储 mysql 数据库。
回答by Haim Evgi
mysqldump
will backup by defaultall the triggersbut NOTthe stored procedures/functions. There are 2 mysqldump parameters that control this behavior:
mysqldump
通过将备份默认情况下所有的触发器,但不是在存储过程/函数。有 2 个 mysqldump 参数控制此行为:
--routines
– FALSE by default--triggers
– TRUE by default
--routines
– 默认为 FALSE--triggers
– 默认为真
so in mysqldump
command , add --routines
like :
所以在mysqldump
命令中,添加--routines
如下:
mysqldump <other mysqldump options> --routines > outputfile.sql
read morein this article
在这篇文章中阅读更多
回答by Usman
May be it's obvious for expert users of MYSQL but I wasted some time while trying to figure out default value would not export functions. So I thought to mention here that --routinesparam needs to be set to true to make it work.
对于 MYSQL 的专家用户来说,这可能是显而易见的,但我在试图找出默认值不会导出函数时浪费了一些时间。所以我想在这里提到--routinesparam 需要设置为 true 才能使其工作。
mysqldump --routines=true -u <user> my_database > my_database.sql
回答by Krishna Vedula
I've created the following script and it worked for me just fine.
我创建了以下脚本,它对我来说很好用。
#! /bin/sh
cd $(dirname backupdb.sh my_db dev_user dev_password
)
DB=
DBUSER=
DBPASSWD=
FILE=$DB-$(date +%F).sql
mysqldump --routines "--user=${DBUSER}" --password=$DBPASSWD $DB > $PWD/$FILE
gzip $FILE
echo Created $PWD/$FILE*
and you call the script using command line arguments.
并且您使用命令行参数调用脚本。
##代码##