Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mysqldump and database users

I'm attempting to assemble all the options that I need for mysqldump to create everything used by my applications database into a single script. This includes the database itself and all the database users/passwords/privileges.

I've got it all figured out with the exception of the user piece... here's what I'm currently using:

mysqldump -h host -u root -p \     --add-drop-database --routines -B database_name > backup.sql 

So, what am I missing?

like image 887
Bobby B Avatar asked Oct 20 '10 21:10

Bobby B


People also ask

Does Mysqldump include users?

user; Knowing this, it's pretty obvious that mysqldump shouldn't do anything with users. However, if you need an answer to exporting/importing users and perms I suggest you check the following article - it helped me out.

Does Mysqldump create database?

Mysqldump is a command-line utility that is used to generate the logical backup of the MySQL database. It produces the SQL Statements that can be used to recreate the database objects and data. The command can also be used to generate the output in the XML, delimited text, or CSV format.

What permissions are needed for Mysqldump?

mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, LOCK TABLES if the --single-transaction option is not used, and (as of MySQL 8.0.


1 Answers

The database users/passwords/privileges are kept in the mysql database, and won't get dumped with your dump command. You'll have to add that database as well to the list of DBs to dump:

mysqldump ... --routines --databases database_name mysql > backup.sql 

or just dump everything:

mysqldump ... --routines --all-databases > backup.sql 
like image 130
Marc B Avatar answered Oct 10 '22 10:10

Marc B