{"id":1524,"date":"2017-02-02T10:25:57","date_gmt":"2017-02-02T10:25:57","guid":{"rendered":"http:\/\/www.fastwebhost.in\/blog\/?p=1524"},"modified":"2019-02-12T04:40:23","modified_gmt":"2019-02-12T04:40:23","slug":"how-to-backup-mysql-databases-via-command-line","status":"publish","type":"post","link":"https:\/\/www.fastwebhost.in\/blog\/how-to-backup-mysql-databases-via-command-line\/","title":{"rendered":"How to Backup MySQL Databases via command line"},"content":{"rendered":"<p style=\"margin-bottom: 10px !important;\">In this tutorial you are going to learn how to backup&nbsp;MySQL databases via command line on Linux server. Also, we&#8217;ll cover restoring a&nbsp;mysql database through command line.<\/p>\n<p style=\"margin-bottom: 10px !important;\">Do you know that MySQL provides an amazing tool to backup and restore databases?<\/p>\n<p>Let&#8217;s dive in and learn about it.<\/p>\n<h4>mysqldump \u2014 A Database Backup Utility<\/h4>\n<p><span><\/span><\/p>\n<p>The <span>mysqldump<\/span> client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server. The <span>mysqldump<\/span> command can also generate output in CSV, other delimited text, or XML format..<\/p>\n<p><span><span style=\"font-size: 19.5px;\"><b>MySQL.COM<\/b><\/span>&nbsp;Definition<\/span><\/p>\n<h4>How to&nbsp;Backup a Database?<\/h4>\n<p>You can use mysqldump command utility to dump database or tables data into textfiles with SQL queries. Later, MySQL can restore database by executing all the SQL queries stored in dumped text files.&nbsp;<\/p>\n<p>There are in general three ways to use <span>mysqldump<\/span>\u2014in order to dump a set of one or more tables, a set of one or more complete databases, or an entire MySQL server\u2014as shown here:<\/p>\n<p><span style=\"font-size: 15px; font-weight: bold;\">mysqldump [<\/span><em style=\"font-size: 15px; font-weight: bold;\">options<\/em><span style=\"font-size: 15px; font-weight: bold;\">] <\/span><em style=\"font-size: 15px; font-weight: bold;\">db_name<\/em><span style=\"font-size: 15px; font-weight: bold;\"> [<\/span><em style=\"font-size: 15px; font-weight: bold;\">tbl_name<\/em><span style=\"font-size: 15px; font-weight: bold;\"> &#8230;]<\/span><span>mysqldump [<em>options<\/em>] &#8211;databases <em>db_name<\/em> &#8230;<\/span><span>mysqldump [<em>options<\/em>] &#8211;all-databases<\/span><\/p>\n<p>If you want to backup single database, execute below command to dump database contents to text file.<\/p>\n<p><span>mysqldump sampledb &nbsp;&gt; &nbsp;sampledb.sql<\/span><\/p>\n<p>To backup multiple databases, execute below command.<\/p>\n<p><span>mysqldump &#8211;databases database_db1 database_db2 &gt; mutilple_databases.sql<\/span><\/p>\n<p>For all databases on server, execute below command.<\/p>\n<p><span>mysqldump &#8211;all-databases &gt; all_databases.sql<\/span><\/p>\n<p>All above commands generates <span>.sql<\/span> file which will be used for restoring databases.<\/p>\n<h3>MySQL Database Command Line Basics<\/h3>\n<p><span><\/span><\/p>\n<ul data-unit=\"px\" style=\"margin-bottom: 10px !important;\">\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-change-reset-mysql-root-password-linux-via-command-line\/\" target=\"_blank\">How to Change or Reset MySQL root Password via Command Line<\/a><\/li>\n<\/ul>\n<ul data-unit=\"px\" style=\"margin-bottom: 10px !important;\">\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-create-a-mysql-database-via-command-line\/\" target=\"_blank\">How to Create a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-select-mysql-database-linux-via-command-line\/\" target=\"_blank\">How to Select a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-delete-a-mysql-database-on-linux-via-command-line\" target=\"_blank\">How to Delete a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-backup-mysql-databases-via-command-line\" target=\"_blank\">How to Backup or Restore a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<h4>How to Restore a Database?<\/h4>\n<p>You can restore MySQL database using dump files ( .sql ) created in earlier steps. The SQL files contain a series of SQL queries so it&#8217;s easy to restore through <span>mysql<\/span>&nbsp;command.<\/p>\n<p>To restore database &#8220;sampledb&#8221; from SQL dump file, use below command.<\/p>\n<p><span>mysql sampledb &nbsp;&lt; &nbsp;sampledb.sql<\/span><\/p>\n<p>In the above command, <span>sampledb<\/span> is the name of the database you want to restore, and <span>sampledb.sql<\/span> is the name of the backup file to be restored.<\/p>\n<p>To restore one particular database from SQL dump file, use below command.<\/p>\n<p><span style=\"font-size: 15px;\">mysql &#8211;one-database sampledb &nbsp;&lt; &nbsp;all_databases.sql<\/span><\/p>\n<p>Once command executed successfully, check your database.<\/p>\n<p>So far, you have learned how to backup database using <span>mysqldump<\/span> tool and restore a database through <span>mysql<\/span> command.<\/p>\n<p>Let us know what you think of this article and we&#8217;d love to hear from you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you are going to learn how to backup&nbsp;MySQL databases via command line on Linux server. Also, we&#8217;ll cover restoring a&nbsp;mysql database through command line. Do you know that MySQL provides an amazing tool to backup and restore databases? Let&#8217;s dive in and learn about it. mysqldump \u2014 A Database Backup Utility The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1542,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_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":[22,20],"tags":[36],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1524"}],"collection":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/comments?post=1524"}],"version-history":[{"count":3,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1524\/revisions"}],"predecessor-version":[{"id":4929,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1524\/revisions\/4929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media\/1542"}],"wp:attachment":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media?parent=1524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/categories?post=1524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/tags?post=1524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}