mysqldump all databases on mysql

I was wondering for a few minutes if I can easily backup all databases created by users on a mysql database server. I was trying to automate the process regardless of users creating new databases without my knowledge. I was aware of the convention under which mysql stores the separate databases on the filesystem so I gave it a try.
Fist I tried with few ‘ls’ commands to retrieve the folder names which respectively referred to the database names in the mysql server. On FreeBSD here is the command I used:

You should note in the code above that I have a .mysqladminpass file in the root folder that contains the mysql server password for the root user. I do this out of laziness but you can supply this argument however you want. Again my plan was automation but you could easily have input for a variable from the keyboard here.

The result is a flawless export of all user databases to the desired backup location.
In my case I worked out some more details so I bzip2 the dumped sql files and added md5 checksums in a separate file for security I am implementing later on but in general this is all you need to backup your mysql user databases.

Quite true.. I didn’t read the man to refresh on the options.
The databases belong to different users and I had to make some sort of separation. The -all-databases option dumps the whole content into one and it’s more difficult to separate it later on.
However this had me thinking of the –database option which would be more useful. I’ll probably rewrite my backup scripts as soon as I get a chance.
Thanks for the comment and have a great weekend!