Linux 重新创建mysql数据库结构和存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3676994/
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
Recreate mysql database structure and stored procedures
提问by tzmatt7447
I have a set of MYSQL tables on the development server that I need to place on the production server. How can I "recreate" all of them?
我在开发服务器上有一组 MYSQL 表,我需要将它们放在生产服务器上。我怎样才能“重新创建”所有这些?
There are triggers present as well (I think). I need to recreate everything.
也存在触发器(我认为)。我需要重新创造一切。
采纳答案by Pekka
Use mysqldump
to create a dump file that you can feed to mysql
on the target server.
使用mysqldump
创建转储文件,您可以喂到mysql
目标服务器上。
To make sure triggers get exported too, use the --triggers
option. (Although I think those are included by default.)
要确保触发器也被导出,请使用该--triggers
选项。(虽然我认为默认情况下包含这些。)
To make sure stored procedures get exported too, use the --routines
option. Note that (emphasis mine):
要确保也导出存储过程,请使用该--routines
选项。请注意(强调我的):
This option was added in MySQL 5.1.2. Before that, stored routines are not dumped.Routine DEFINER values are not dumped until MySQL 5.1.8. This means that before 5.1.8, when routines are reloaded, they will be created with the definer set to the reloading user. If you require routines to be re-created with their original definer, dump and load the contents of the mysql.proc table directly as described earlier.
这个选项是在 MySQL 5.1.2 中添加的。在此之前,不会转储存储的例程。直到 MySQL 5.1.8 才会转储常规 DEFINER 值。这意味着在 5.1.8 之前,当例程被重新加载时,它们将使用设置为重新加载用户的定义者创建。如果您需要使用其原始定义器重新创建例程,请按照前面所述直接转储和加载 mysql.proc 表的内容。
回答by Kavet Kerek
Use mysqldump (documentation located here). If you do not specify tables it assumes all tables. You can also explicitly choose tables to copy or to ignore. You can tell it to create drop statements before your create statements. It takes cares of triggers but I forget if it takes care of routines, you'll have to take a look.
使用 mysqldump(位于此处的文档)。如果您不指定表,则它假定所有表。您还可以明确选择要复制或忽略的表。您可以告诉它在创建语句之前创建 drop 语句。它负责触发器,但我忘记了如果它负责例程,您将不得不看一看。