We want to export a large amount of tables and routines and we've do this often. Each database, table and routine should be dumped with one exception: a procedure with a specific name. So I was wondering, is there a way to exclude only procedure from the dump?

For tables there is an "ignore-table" option in MySQL. Is there something similar or a workaround to do this for one procedures in particular?


There is no built-in way to do so with mysqldump. However, all is not lost, you should be able to get away with it using sed.

Let's say your routine is a function, which is called split_token. The following code:

mysqldump --all-databases ... | sed "/DROP FUNCTION IF EXISTS \`split_token\`/,/^DELIMITER ;$/d"

will disregard the lines starting with DROP FUNCTION... and until the DELIMITER statement which ends the function's definition.

The above does not verify:

  1. A function of the same name may exist in multiple databases
  2. The text may appear within a string -- need better regexp matching (try and match the code starting the line using ^ -- look at the following line:

    /*!50003 DROP FUNCTION IF EXISTS split_token */;

Leaving this up to you to find the best regular expression.

| improve this answer | |
  • Thanks! This should work. However we are using Windows - so we can't use 'sed'. At least to my knowlegde Windows doesn't have a similar command. But I think this should help out: gnuwin32.sourceforge.net/packages/sed.htm – user18247 Jan 23 '13 at 10:22
  • Take a look at cygwin. It's been a while since I last used it (and a while since I last used Windows) -- but it should do the trick. – Shlomi Noach Jan 23 '13 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.