3

this is probably massively simple, however I will be doing this for a live server and don't want to mess it up.

Can someone please let me know how I can do a mysqldump of all databases, procedures, triggers etc except the mysql and performance_schema databases?

Neekoy
  • 2,325
  • 5
  • 29
  • 48

3 Answers3

8

Yes, you can dump several schemas at the same time :

mysqldump --user=[USER] --password=[PASS] --host=[HOST] --databases mydb1 mydb2 mydb3 [...] --routines > dumpfile.sql

OR

mysqldump --user=[USER] --password=[p --host=[HOST] --all-databases --routines > dumpfile.sql

concerning the last command, if you don't want to dump performance_schema (EDIT: as mentioned by @Barranka, by default mysqldump won't dump it), mysql, phpMyAdmin schema, etc. you just need to ensure that [USER] can't access them.

Basile
  • 326
  • 1
  • 7
2

There's no option in mysqldump that you could use to filter the databases list, but you can run two commands:

# DATABASES=$(mysql -N -B -e "SHOW DATABASES" | grep -Ev '(mysql|performance_schema)')
# mysqldump -B $DATABASES
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
2

As stated in the reference manual:

mysqldump does not dump the INFORMATION_SCHEMA or performance_schema database by default. To dump either of these, name it explicitly on the command line and also use the --skip-lock-tables option. You can also name them with the --databases option.

So that takes care of your concern about dumping those databases.

Now, to dump all databases, I think you should do something like this:

mysqldump -h Host -u User -pPassword -A -R > very_big_dump.sql

To test it without dumping all data, you can add the -d flag to dump only database, table (and routine) definitions with no data.

As mentioned by Basile in his answer, the easiest way to ommit dumping the mysql database is to invoke mysqldump with a user that does not have access to it. So the punch line is: use or create a user that has access only to the databases you mean to dump.

Barranka
  • 20,547
  • 13
  • 65
  • 83
  • as you mentioned INFORMATION_SCHEMA or performance_schema won't be dumped by default, but `mysql` will be. – Basile Sep 24 '15 at 21:52