HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlCritical

Dump only the Stored Procedures in MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storeddumpproceduresthemysqlonly

Problem

I need to dump only the stored procedures : no data, no table creation. How can I do this using mysqldump?

Solution

This should do it for you:

mysqldump -h yourhost -u username -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
  -h                     host replace yourhost with name of host
  -u                     username, replace username with username
  -p                     when added will ask for password. 
                         --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.


CAVEAT

It would be much better not to separate the stored procedures from the database so that specific stored procedures will be created in the database it was meant for. The same goes for triggers. This would be preferrable:

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

Code Snippets

mysqldump -h yourhost -u username -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
  -h                     host replace yourhost with name of host
  -u                     username, replace username with username
  -p                     when added will ask for password. 
                         --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.
mysqldump -h... -u... -p... -d --routines --triggers --all-databases > MySQLStoredProc.sql

Context

StackExchange Database Administrators Q#4086, answer score: 54

Revisions (0)

No revisions yet.