使用 mysqldump 进行完美备份
如何使用mysqldump对mysql数据库进行完美备份? 当我进行备份时,只会备份指定数据库中的表。 过程和功能不是。
这是我正在使用的备份命令: (操作系统为Windows Vista。)
mysqldump -u username -p db1 > backup.sql
How can I make a perfect backup of mysql database using mysqldump?
When I am making a backup, my tables from specified database are only getting backed up. The procedures and functions are not.
Here's the backup command I am using:
(Operating system is Windows Vista.)
mysqldump -u username -p db1 > backup.sql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您想在不中断任何连接的情况下进行完整备份,即所有数据库、过程、例程和事件:
-A
对于所有数据库(您也可以使用--all-databases< /code>)
-R
对于所有例程(存储过程和触发器)-E
对于所有事件--single-transaction
不锁定即,不中断任何连接(读/写)。如果您只想备份指定的数据库:
如果您只想备份数据库中的特定表:
如果您只想备份数据库结构,只需添加
-- no-data
到前面的命令:mysqldump
还有更多选项,这些选项都记录在mysqldump
文档 或在命令行运行man mysqldump
。If you want to take a full backup i.e., all databases, procedures, routines, and events without interrupting any connections:
-A
For all databases (you can also use--all-databases
)-R
For all routines (stored procedures & triggers)-E
For all events--single-transaction
Without locking the tables i.e., without interrupting any connection (R/W).If you want to take a backup of only specified database(s):
If you want to take a backup of only a specific table in a database:
If you want to take a backup of the database structure only just add
--no-data
to the previous commands:mysqldump
has many more options, which are all documented in themysqldump
documentation or by runningman mysqldump
at the command line.这有点取决于你的版本。 在 5.0.13 之前,这对于 mysqldump 是不可能的。
来自 mysqldump 手册页 (v 5.1.30)
It depends a bit on your version. Before 5.0.13 this is not possible with mysqldump.
From the mysqldump man page (v 5.1.30)
使用这些命令:-
如果我们只想备份存储过程和触发器而不是 mysql 表和数据,那么我们应该运行如下命令:
如果您需要将它们导入到另一个数据库/服务器,则必须运行如下命令:
Use these commands :-
If we want to backup ONLY the stored procedures and triggers and not the mysql tables and data then we should run something like:
If you need to import them to another db/server you will have to run something like:
除了 --routines 标志之外,您还需要授予备份用户读取存储过程的权限:
我为备份用户授予的最小 GRANT 权限集是:
In addition to the --routines flag you will need to grant the backup user permissions to read the stored procedures:
My minimal set of GRANT privileges for the backup user are:
我使用的是 MySQL 5.5.40。 此版本有选项
--all-databases
该命令将为 MySQL 服务器中的所有数据库创建一个完美的备份,并保存到以当前日期时间命名的文件中。
I am using MySQL 5.5.40. This version has the option
--all-databases
This command will create a perfect backup of all databases in MySQL server to file named to current date-time.
使用“-R”来备份存储过程,但还要记住,如果您希望在修改数据库时对其进行一致的转储,则需要使用
--single-transaction
(如果您只备份innodb) 或--lock-all-tables
(如果您还需要 myisam 表)Use '-R' to backup stored procedures, but also keep in mind that if you want a consistent dump of your database while its being modified you need to use
--single-transaction
(if you only backup innodb) or--lock-all-tables
(if you also need myisam tables)在 MySQL 5.7 上它对我有用,我使用的是 CentOS7。
用于转储。
命令:
示例:
用于部署转储。
命令:
示例:
On MySQL 5.7 its work for me, I'm using CentOS7.
For taking Dump.
Command :
Exemple :
For deploying Dump.
Command :
Exemple :
要创建转储,请按照以下步骤操作:
打开 CMD 并转到安装 MySQL 的 bin 文件夹
例如:C:\Program Files\MySQL\MySQL Server 8.0\bin。 如果你看到这里
文件夹 mysqldump.exe 将在那里。 或者你已经设置了上面的文件夹
在环境变量的 Path 变量中。
现在,如果你在 CMD 中点击 mysqldump,你可以看到 CMD 能够识别 dump 命令。
To create dump follow below steps:
Open CMD and go to bin folder where you have installed your MySQL
ex:C:\Program Files\MySQL\MySQL Server 8.0\bin. If you see in this
folder mysqldump.exe will be there. Or you have setup above folder
in your Path variable of Environment Variable.
Now if you hit mysqldump in CMD you can see CMD is able to identify dump command.
例如,使用 -E(--events)、-R(--routines) 和默认情况下隐式使用 --triggers ,您可以导出
apple
数据库表的架构和数据及其 事件,例程 (过程和函数) 和触发器到backup.sql
,如下所示。 *--single-transaction 保证一致(可靠)转储,不可能仅导出过程或函数和 --skip-triggers 可以排除默认包含在隐式--triggers
中的触发器和 我的回答解释了如何导出数据库表的架构和数据:或:
或。 *您可以显式使用
--triggers
,如下所示::并且,使用 -B(--databases),可以导出
apple
和orange
数据库的架构和数据及其事件backup.sql
的例程(过程和函数)和触发器,如下所示。 *我的回答解释了如何导出多个数据库:并且,使用 -A(--all -databases),您可以将所有数据库的架构和数据及其所有事件、例程(过程和函数)和触发器导出到
backup.sql
,如下所示。 *我的回答解释了如何导出所有数据库:For example, using -E(--events), -R(--routines) and --triggers implicitly used by default, you can export the schema and data of the tables of
apple
database with its events, routines (procedures and functions) and triggers tobackup.sql
as shown below. *--single-transaction guarantees consistent(reliable) dump and it is impossible to export only procedures or functions and --skip-triggers can exclude the triggers which are included with implicit--triggers
by default and my answer explains how to export the schema and data of the tables of a database:Or:
Or. *You can explicitly use
--triggers
as shown below::And, using -B(--databases), you can export the schema and data of
apple
andorange
databases with their events, routines (procedures and functions) and triggers tobackup.sql
as shown below. *My answer explains how to export the schema and data of multiple databases:And, using -A(--all-databases), you can export the schema and data of all databases with all their events, routines (procedures and functions) and triggers to
backup.sql
as shown below. *My answer explains how to export the schema and data of all databases: