仅转储 MySQL 中的存储过程

nak*_*hli 41 mysql mysqldump backup stored-procedures dump

我只需要转储存储过程:没有数据,没有表创建。如何使用 mysqldump 执行此操作?

Rol*_*DBA 45

这应该为你做:

mysqldump -h... -u... -p... -n -d -t --routines --triggers --all-databases > MySQLStoredProc.sql

  -n, --no-create-db     Suppress the CREATE DATABASE ... IF EXISTS statement 
                         that normally is output for each dumped database if
                         --all-databases or --databases is given.
  -d, --no-data          No row information.
  --triggers             Dump triggers for each dumped table.
                         (Defaults to on; use --skip-triggers to disable.)
  -R, --routines         Dump stored routines (functions and procedures).
  -t, --no-create-info   Do not write CREATE TABLE statements that create each 
                         dumped table.
Run Code Online (Sandbox Code Playgroud)

警告

最好不要将存储过程从数据库中分离出来,这样特定的存储过程将在它所针对的数据库中创建。触发器也是如此。这将是可取的:

mysqldump -h... -u... -p... -d --routines --triggers --all-databases > MySQLStoredProc.sql
Run Code Online (Sandbox Code Playgroud)

  • 我试过了,不得不添加'-t'选项来不获取创建表语句。 (11认同)