{"id":47,"date":"2020-01-22T22:38:01","date_gmt":"2020-01-22T22:38:01","guid":{"rendered":"https:\/\/serverhub.com\/kb\/?p=47"},"modified":"2020-01-22T22:53:26","modified_gmt":"2020-01-22T22:53:26","slug":"how-to-create-a-mysql-backup-using-command-line","status":"publish","type":"post","link":"https:\/\/serverhub.com\/kb\/how-to-create-a-mysql-backup-using-command-line\/","title":{"rendered":"How to Create a mySQL Backup using Command Line"},"content":{"rendered":"\n<p> Whether you&#8217;re running a LAMP stack on Ubuntu or CentOS, it is usually very good practice to back up your MySQL databases to prevent data loss. <\/p>\n\n\n\n<p>Here we will teach you how to do this with the help of the mysqldump command. <\/p>\n\n\n\n<p> Your&nbsp;<a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/www.ubuntu.com\" target=\"_blank\">Ubuntu Server<\/a> is now up and running with a LAMP stack in your data center, and on that server you setup yourself runs a database or maybe even a few databases for that matter. Things are getting exciting and then you remember. They must be backed up. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What you will need <\/h2>\n\n\n\n<p>If you already have MySQL up and running and all the necessary software is already installed, you are already on the right track. <br><br>In order to start this task of backup, you will need to make sure that you have the password for the MySQL user that has access permissions to the database(s) in question. <br><\/p>\n\n\n\n<p>MySQL provides a great command line utility to take backups of your MySQL database. <strong>mysqldump&nbsp;<\/strong>command line utility is available with MySQL installation (bin directory) and can be used to achieve this. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step by Step<br><br><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to your server with root user<\/li><li><\/li><li>Use following command for taking backup of your MySQL database using mysqldump utility.<\/li><\/ol>\n\n\n\n<p>mysqldump \u2013u[user name] \u2013p[password] [database name] &gt; [dump file]<\/p>\n\n\n\n<p> Now to make sure the command was executed and the backup file was created using the command <\/p>\n\n\n\n<p>ls \u2013l<\/p>\n\n\n\n<p>on the same path and you should see the database backup file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"mce_12\">Backing it all up<\/h2>\n\n\n\n<p>Don&#8217;t want to just backup one database? No Problem! <\/p>\n\n\n\n<p>If you want to back up all of your databases, you can accomplish this with the&nbsp;<em>&#8211;all-databases<\/em>&nbsp;option, like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysqldump -u USER -p --all-databases &gt; \/mnt\/backups\/all_databases.sql<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"mce_22\">And That&#8217;s It!<\/h2>\n\n\n\n<p>Congrats! You&#8217;ve successfully backed up your MySQL databases successfully. Now save them somewhere safe, and hopefully you&#8217;ll never need to revert them due to a failure. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you&#8217;re running a LAMP stack on Ubuntu or CentOS, it is usually very good practice to back up your MySQL databases to prevent data loss. Here we will teach you how to do this with the help of the mysqldump command. Your&nbsp;Ubuntu Server is now up and running with a LAMP stack in your &#8230; <a title=\"How to Create a mySQL Backup using Command Line\" class=\"read-more\" href=\"https:\/\/serverhub.com\/kb\/how-to-create-a-mysql-backup-using-command-line\/\" aria-label=\"More on How to Create a mySQL Backup using Command Line\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[7],"tags":[24,10,23],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-linux-administration","tag-databases","tag-linux-administration","tag-mysql"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":0,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}