Dump and restore all MySQL databases with users

Last time I must reinstall my MacOS and configure all my development environment again. It wasn’t a big issues except MySQL database and users, becase there are a lot of databases, each with different credentials. I had to move all the data, because test app needs it. The question was: how can I dump not only databases using mysqldump, but also all users and all privileges? Fortunately, solution is very simple and mysqldump allows us to get all in only one command, so there is quick tip to dump all data:

mysqldump -uroot -p --flush-privileges --routines --all-databases > backup.sql

And then we can restore whole data on new server using standard mysql command:

mysql -uroot -p < backup.sql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.