MyS*_*DBA 47 mysql backup mysqldump complete
如何使用mysqldump完成mysql数据库的完整备份?当我进行备份时,我的指定数据库中的表只会被备份.程序和功能不是.
这是我正在使用的备份命令:(
操作系统是Windows Vista.)
mysqldump -u username -p db1 > backup.sql
Run Code Online (Sandbox Code Playgroud)
小智 75
如果要在不中断任何连接的情况下进行完整备份,即所有数据库,过程,例程和事件:
mysqldump -u [username] -p -A -R -E --triggers --single-transaction > full_backup.sql
Run Code Online (Sandbox Code Playgroud)
-A对于所有数据库(您也可以使用--all-databases)-R 对于所有例程(存储过程和触发器)-E 对于所有活动--single-transaction 不锁定表,即不中断任何连接(R/W).如果要仅备份指定的数据库:
mysqldump -u [username] -p [database_name] [other_database_name] -R -e --triggers --single-transaction > database_backup.sql
Run Code Online (Sandbox Code Playgroud)
如果要仅备份数据库中的特定表:
mysqldump -u [username] -p [database_name] [table_name] > table_backup.sql
Run Code Online (Sandbox Code Playgroud)
如果要备份数据库结构,只需添加--no-data到以前的命令:
mysqldump -u [username] –p[password] –-no-data [database_name] > dump_file.sql
Run Code Online (Sandbox Code Playgroud)
mysqldump还有更多选项,这些选项都记录在mysqldump文档中或通过man mysqldump在命令行运行.
Knu*_*gen 16
这取决于你的版本.在5.0.13之前,使用mysqldump是不可能的.
来自mysqldump手册页(v 5.1.30)
--routines, -R
Dump stored routines (functions and procedures) from the dumped
databases. Use of this option requires the SELECT privilege for the
mysql.proc table. The output generated by using --routines contains
CREATE PROCEDURE and CREATE FUNCTION statements to re-create the
routines. However, these statements do not include attributes such
as the routine creation and modification timestamps. This means that
when the routines are reloaded, they will be created with the
timestamps equal to the reload time.
...
This option was added in MySQL 5.0.13. Before that, stored routines
are not dumped. Routine DEFINER values are not dumped until MySQL
5.0.20. This means that before 5.0.20, 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.
Run Code Online (Sandbox Code Playgroud)
小智 15
使用这些命令: -
mysqldump <other mysqldump options> --routines > outputfile.sql
Run Code Online (Sandbox Code Playgroud)
如果我们只想备份存储过程和触发器而不是mysql表和数据,那么我们应该运行如下:
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql
Run Code Online (Sandbox Code Playgroud)
如果需要将它们导入另一个数据库/服务器,则必须运行如下操作:
mysql <database> < outputfile.sql
Run Code Online (Sandbox Code Playgroud)
除了--routines标志之外,您还需要授予备份用户读取存储过程的权限:
GRANT SELECT ON `mysql`.`proc` TO <backup user>@<backup host>;
Run Code Online (Sandbox Code Playgroud)
我为备份用户设置的最小GRANT权限是:
GRANT USAGE ON *.* TO ...
GRANT SELECT, LOCK TABLES ON <target_db>.* TO ...
GRANT SELECT ON `mysql`.`proc` TO ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
158537 次 |
| 最近记录: |