{"id":4987,"date":"2020-04-02T14:54:53","date_gmt":"2020-04-02T18:54:53","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=4987"},"modified":"2020-04-03T10:40:52","modified_gmt":"2020-04-03T14:40:52","slug":"how-to-backup-and-restore-mysql-database","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/","title":{"rendered":"How to Backup and Restore Mysql Database"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg\" alt=\"How to backup and restore MySQL Databases\" class=\"wp-image-4988\"\/><\/figure>\n\n\n\n<p>If you are a database administrator and responsible for managing <a href=\"https:\/\/fr.wikipedia.org\/wiki\/MySQL\">MySQL server<\/a> then you must have a knowledge of how to backup and restore the MySQL database. Regularly backing up MySQL database is a good practice for any database administrator as this will help you to prevent data loss if your <a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\">server<\/a> goes down. There are several ways to perform backup operations of MySQL databases.<\/p>\n\n\n\n<p>In this tutorial, we will explain how to backup and restore the MySQL database in Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>A <a href=\"https:\/\/www.globo.tech\/dedicated-server-hosting\">server<\/a> running <a href=\"https:\/\/help.ubuntu.com\/\">Ubuntu<\/a> 18.04 with MySQL installed.<\/li><li>An existing Database.<\/li><li>You must know your database user and password.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Backup a Single MySQL Database<\/h2>\n\n\n\n<p>You can backup and restore the MySQL database using the mysqldump utility. This utility will help you to backup a local or remote MySQL database into a single file.<\/p>\n\n\n\n<p>You can backup a single MySQL database using the following syntax:<\/p>\n\n\n\n<p><code>mysqldump -v -u [Username] \u2013p[Password] [Database_name] &gt; [Dump_file.sql]<\/code><\/p>\n\n\n\n<p><strong>A brief explanation of each parameter is shown below:<\/strong><\/p>\n\n\n\n<p><strong>Username :<\/strong> Specify the MySQL username.<br><strong>Password :<\/strong> Specify the password of the MySQL user.<br><strong>Database_name :<\/strong> A name of the database that you want to backup.<br><strong>Dump_file.sql :<\/strong> A name of the dump file that you want to generate.<\/p>\n\n\n\n<p>For example, to take a backup of a single database named testdb and generates a dump file named testdb_backup.sql, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -v -u root \u2013proot-password testdb &gt; testdb_backup.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-1.png\" alt=\"Output of mysqldump command.\" class=\"wp-image-4989\" width=\"647\" height=\"152\"\/><\/figure>\n\n\n\n<p>The above command will backup the testdb database into a file called testdb_backup.sql.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Backup Multiple Databases<\/h2>\n\n\n\n<p>In some cases, you may need to backup more than one database. In this case, you can perform this operation using the &#8211;<strong>-databases<\/strong> option.<\/p>\n\n\n\n<p>For example, to take a backup of a database named test1db and test2db, and generates a dump file named testdb.sql, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -v --user=root --password=root-password --databases test1db test2db &gt; testdb.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-2.png\" alt=\"Output of mysqldump command for multiples databases.\" class=\"wp-image-4990\" width=\"762\" height=\"71\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Backup All Databases<\/h2>\n\n\n\n<p>You can also backup all MySQL databases in your system using the <strong>&#8211;all-databases<\/strong> option.<\/p>\n\n\n\n<p>For example, backup all databases in your system and generates a single dump file named alldb.sql, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -u root \u2013proot-password --all-databases  &gt; alldb.sql<\/code><\/p>\n\n\n\n<p>It is also possible to backup all databases in your system and generates a separate dump file for each database. You can achieve this with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for DATABASE in $(mysql --user=root --password=root-password -e 'show databases' -s --skip-column-names); do\nmysqldump --user=root --password=root-password $DATABASE > \"$DATABASE.sql\";\ndone<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Backup MySQL Database with Compression<\/h2>\n\n\n\n<p>If your database is very large, you will need to compress the dump file to save the disk space. You can achieve this with gzip utility.<\/p>\n\n\n\n<p><code>mysqldump -v -u root -proot-password compressdb | gzip &gt; compressdb_backup.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-3.png\" alt=\"Output of mysqldump command with compression.\" class=\"wp-image-4991\" width=\"666\" height=\"78\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Backup Table Of MySQL Database<\/h2>\n\n\n\n<p>You can also backup a specific table or multiple tables of MySQL database using the following syntax:<\/p>\n\n\n\n<p><code>mysqldump -u root -proot-password [Database_name] [Table_name] &gt; Dump_file.sql<\/code><\/p>\n\n\n\n<p>For example, to take a backup of a single table named table1 from the database testdb, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -v -u root -proot-password testdb table1 &gt; testdb_table1.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-4.png\" alt=\"Output of mysqldump command to backup a specific table only.\" class=\"wp-image-4992\" width=\"712\" height=\"116\"\/><\/figure>\n\n\n\n<p>To take a backup of multiple tables named table1 and table2 from the database testdb, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -v -u root -proot-password testdb table1 table2  &gt; testdb_table.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-5.png\" alt=\"Output of mysqldump command to backup multiple tables.\" class=\"wp-image-4993\" width=\"736\" height=\"152\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Backup Remote MySQL Database<\/h2>\n\n\n\n<p>It is also possible to take a backup of the database from the remote MySQL server. In order to backup the remote MySQL database, you target MySQL must be configured to allow remote connection.<\/p>\n\n\n\n<p>For example, to take a backup of a database named remotedb from the remote MySQL server 192.168.0.100, run the following command:<\/p>\n\n\n\n<p><code>mysqldump -v -h 192.168.0.100 -u root -proot-password remotedb &gt; remotedb_backup.sql<\/code><\/p>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysqldump-output-6.png\" alt=\"Output of mysqldump command to backup a database from a remote MySQL server.\" class=\"wp-image-4994\" width=\"773\" height=\"73\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Restore MySQL Database<\/h2>\n\n\n\n<p>In order to restore a database on the target computer, you will need to create an empty database on the target computer.<\/p>\n\n\n\n<p>For example, to restore a database named testdb, log into the target computer and create an empty database with the following command:<\/p>\n\n\n\n<p><code>mysql -v -u root -proot-password -e \"create database testdb\";<\/code><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/mysql-output.png\" alt=\"Mysql command to create an empty database.\" class=\"wp-image-4995\" width=\"553\" height=\"107\"\/><\/figure>\n\n\n\n<p>Next, restore the database from the dump file testdb_backup.sql with the following command:<\/p>\n\n\n\n<p><code>mysql -v -u root -proot-password testdb &lt; testdb_backup.sql<\/code><\/p>\n\n\n\n<p>Once the command is successfully executed, you do not receive any feedback, and return to the command prompt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In the above guide, you learned several methods to backup and restore MySQL database with practical examples. I hope this will helps you to simplify your database administration task and save a lot of time.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":4988,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-4987","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Backup and Restore Mysql Database - Globo.Tech<\/title>\n<meta name=\"description\" content=\"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Backup and Restore Mysql Database - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-02T18:54:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-03T14:40:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/\",\"name\":\"How to Backup and Restore Mysql Database - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg\",\"datePublished\":\"2020-04-02T18:54:53+00:00\",\"dateModified\":\"2020-04-03T14:40:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg\",\"contentUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg\",\"width\":1200,\"height\":628,\"caption\":\"How to backup and restore MySQL database\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Backup and Restore Mysql Database\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Backup and Restore Mysql Database - Globo.Tech","description":"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/","og_locale":"en_US","og_type":"article","og_title":"How to Backup and Restore Mysql Database - Globo.Tech","og_description":"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.","og_url":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/","og_site_name":"Globo.Tech","article_published_time":"2020-04-02T18:54:53+00:00","article_modified_time":"2020-04-03T14:40:52+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg","type":"image\/jpeg"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/","url":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/","name":"How to Backup and Restore Mysql Database - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage"},"image":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg","datePublished":"2020-04-02T18:54:53+00:00","dateModified":"2020-04-03T14:40:52+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"MySQL Server is a opensource database engine that is very popular for Linux servers. Read this article and learn how to Backup and Restore Mysql Database.","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#primaryimage","url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg","contentUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2020\/04\/backup-restore-mysql-database.jpg","width":1200,"height":628,"caption":"How to backup and restore MySQL database"},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-backup-and-restore-mysql-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to Backup and Restore Mysql Database"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=4987"}],"version-history":[{"count":5,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4987\/revisions"}],"predecessor-version":[{"id":5001,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4987\/revisions\/5001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media\/4988"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=4987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=4987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=4987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}