Am trying to backup my databases through the terminal in Ubuntu using the mysqldump command and it's successful , but where does it place the backed up databases ?

migrated from Mar 1 '11 at 13:47

This question came from our site for professional and enthusiast programmers.

By default it does it to the console. You need to redirect the output to a file if you need to save it.

  • 1
    I run the command like this "$ mysqldump -h localhost -u username - p database_name > back_up_db.sql" but have no idea where "back_up_db.sql " is stored. – Opolot Jerry Collins Mar 1 '11 at 10:54
  • 2
    In this case, in the same directory as you ran the command – JohnC Mar 1 '11 at 11:04
  • 1
    It is stored in your current directory. After you run the command, do $ pwd. That will tell you which directory you're in. – Novikov Mar 1 '11 at 11:05
  • But where should you put backups? For example on Ubuntu. Why does nobody seem to care about that? They just create a backup in whichever directory they're in... seems like a way to make your server a complete mess. – BadHorsie Dec 17 '15 at 17:12
  • The place you put the backup is up to you. Ideally, it should be on a different machine in a different physical location. This is why you usually do a remote MySQL dump over SSH and get the data on a different machine. You just pipe the console output over ssh into a file on a different machine. – Rasika Dec 18 '15 at 3:59

It should also be noted that the mysqldump command also has a switch for a destination file.

--result-file=file_name, -r file_name

Usually you use mysql dump like this

mysqldump -h host -u user -ppassword dbname > dumpfile

So the output is whatever file you redirect output to. The output file will contain instructions that will rebuild the database from scratch, including the schema, if your run it on a new install like so.

mysql -h host -u user -ppassword dbname < dumpfile

Here's wiki on IO redirection

It will be stored in the path or folder from where you run the mysql commandenter image description here suppose you run the command from root then it will be stored in the root directory

you can see my backup file skillmappingcleardata.sql in the root directory because I run the mysql command from there

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.