{"id":13414,"date":"2019-04-02T02:07:57","date_gmt":"2019-04-02T02:07:57","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13414"},"modified":"2019-04-02T02:07:57","modified_gmt":"2019-04-02T02:07:57","slug":"mysql-backup-and-restore-commands-for-database-administration","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/02\/mysql-backup-and-restore-commands-for-database-administration\/","title":{"rendered":"MySQL Backup and Restore Commands for Database Administration"},"content":{"rendered":"<p>This article shows you several practical examples on how to perform various backup operations of\u00a0<strong>MySQL<\/strong>databases using\u00a0<strong>mysqldump<\/strong>\u00a0command and also we will see how to restore them with the help of\u00a0<strong>mysql<\/strong>\u00a0and\u00a0<strong>mysqlimport<\/strong>\u00a0command in\u00a0<strong>Linux<\/strong>.<\/p>\n<p><strong>mysqldump<\/strong>\u00a0is a command-line client program, it is used to dump local or remote\u00a0<strong>MySQL<\/strong>\u00a0database or collection of databases for backup into a single flat file.<\/p>\n<div id=\"attachment_1518\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/11\/MySQL-Backup-and-Restore.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1518\" title=\"How to backup mysql database\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/11\/MySQL-Backup-and-Restore-300x227.jpg\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/11\/MySQL-Backup-and-Restore-300x227.jpg 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/11\/MySQL-Backup-and-Restore.jpg 466w\" alt=\"How to backup mysql database\" width=\"300\" height=\"227\" aria-describedby=\"caption-attachment-1518\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-1518\" class=\"wp-caption-text\">How to Backup and Restore MySQL Database<\/p>\n<\/div>\n<p>We assume that you already have\u00a0<strong>MySQL<\/strong>\u00a0installed on\u00a0<strong>Linux<\/strong>\u00a0system with administrative privileges and we assume that you already have a small amount of knowledge on\u00a0<strong>MySQL<\/strong>. If you don\u2019t have MySQL installed or don\u2019t have any exposure to\u00a0<strong>MySQL<\/strong>\u00a0then read our articles below.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-mysql-on-rhel-centos-6-5-fedora-17-12\/\" target=\"_blank\" rel=\"noopener\">Install MySQL Server on RHEL\/CentOS 6-5, Fedora 17-12<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/mysqladmin-commands-for-database-administration-in-linux\/\" target=\"_blank\" rel=\"noopener\">20 MySQL Commands for Database Administration<\/a><\/li>\n<\/ol>\n<h3>How to Backup MySQL Database?<\/h3>\n<p>To take a backup of\u00a0<strong>MySQL<\/strong>\u00a0database or databases, the database must exist in the database server and you must have access to it. The format of the command would be.<\/p>\n<pre># mysqldump -u [username] \u2013p[password] [database_name] &gt; [dump_file.sql]<\/pre>\n<p>The parameters of the said command as follows.<\/p>\n<ol>\n<li><strong>[username]<\/strong>\u00a0: A valid MySQL username.<\/li>\n<li><strong>[password]<\/strong>\u00a0: A valid MySQL password for the user.<\/li>\n<li><strong>[database_name]<\/strong>\u00a0: A valid Database name you want to take backup.<\/li>\n<li><strong>[dump_file.sql]<\/strong>\u00a0: The name of backup dump file you want to generate.<\/li>\n<\/ol>\n<h4>How to Backup a Single MySQL Database?<\/h4>\n<p>To take a backup of single database, use the command as follows. The command will dump database [<strong>rsyslog<\/strong>] structure with data on to a single dump file called\u00a0<strong>rsyslog.sql<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint rsyslog &gt; rsyslog.sql<\/pre>\n<h4>How to Backup Multiple MySQL Databases?<\/h4>\n<p>If you want to take backup of multiple databases, run the following command. The following example command takes a backup of databases [<strong>rsyslog<\/strong>,\u00a0<strong>syslog<\/strong>] structure and data in to a single file called\u00a0<strong>rsyslog_syslog.sql<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint --databases rsyslog syslog &gt; rsyslog_syslog.sql<\/pre>\n<h4><a name=\"mysqldump\"><\/a>How to Backup All MySQL Databases?<\/h4>\n<p>If you want to take backup of all databases, then use the following command with option\u00a0<strong>\u2013all-database<\/strong>. The following command takes the backup of all databases with their structure and data into a file called\u00a0<strong>all-databases.sql<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint --all-databases &gt; all-databases.sql<\/pre>\n<h4>How to Backup MySQL Database Structure Only?<\/h4>\n<p>If you only want the backup of database structure without data, then use the option\u00a0<strong>\u2013no-data<\/strong>\u00a0in the command. The below command exports database [<strong>rsyslog<\/strong>]\u00a0<strong>Structure<\/strong>\u00a0into a file\u00a0<strong>rsyslog_structure.sql<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint -\u2013no-data rsyslog &gt; rsyslog_structure.sql<\/pre>\n<h4>How to Backup MySQL Database Data Only?<\/h4>\n<p>To backup database\u00a0<strong>Data<\/strong>\u00a0only without structure, then use the option\u00a0<strong>\u2013no-create-info<\/strong>\u00a0with the command. This command takes the database [<strong>rsyslog<\/strong>]\u00a0<strong>Data<\/strong>\u00a0 into a file\u00a0<strong>rsyslog_data.sql<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint --no-create-db --no-create-info rsyslog &gt; rsyslog_data.sql<\/pre>\n<h4>How to Backup Single Table of Database?<\/h4>\n<p>With the below command you can take backup of single table or certain tables of your database. For example, the following command only take backup of\u00a0<strong>wp_posts<\/strong>\u00a0table from the database\u00a0<strong>wordpress<\/strong>.<\/p>\n<pre># mysqldump -u root -ptecmint wordpress wp_posts &gt; wordpress_posts.sql<\/pre>\n<h4>How to Backup Multiple Tables of Database?<\/h4>\n<p>If you want to take backup of multiple or certain tables from the database, then separate each table with space.<\/p>\n<pre># mysqldump -u root -ptecmint wordpress wp_posts wp_comments &gt; wordpress_posts_comments.sql<\/pre>\n<h4>How to Backup Remote MySQL Database<\/h4>\n<p>The below command takes the backup of remote server [<strong>172.16.25.126<\/strong>] database [<strong>gallery<\/strong>] into a local server.<\/p>\n<pre># mysqldump -h 172.16.25.126 -u root -ptecmint gallery &gt; gallery.sql<\/pre>\n<h3>How to Restore MySQL Database?<\/h3>\n<p>In the above tutorial we have seen the how to take the backup of databases, tables, structures and data only, now we will see how to restore them using following format.<\/p>\n<pre># # mysql -u [username] \u2013p[password] [database_name] &lt; [dump_file.sql]<\/pre>\n<h4>How to Restore Single MySQL Database<\/h4>\n<p>To restore a database, you must create an empty database on the target machine and restore the database using\u00a0<strong>msyql<\/strong>\u00a0command. For example the following command will restore the\u00a0<strong>rsyslog.sql<\/strong>\u00a0file to the\u00a0<strong>rsyslog<\/strong>database.<\/p>\n<pre># mysql -u root -ptecmint rsyslog &lt; rsyslog.sql<\/pre>\n<p>If you want to restore a database that already exist on targeted machine, then you will need to use the\u00a0<strong>mysqlimport<\/strong>\u00a0command.<\/p>\n<pre># mysqlimport -u root -ptecmint rsyslog &lt; rsyslog.sql<\/pre>\n<p>In the same way you can also restore database tables, structures and data. If you liked this article, then do share it with your friends.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/mysql-backup-and-restore-commands-for-database-administration\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows you several practical examples on how to perform various backup operations of\u00a0MySQLdatabases using\u00a0mysqldump\u00a0command and also we will see how to restore them with the help of\u00a0mysql\u00a0and\u00a0mysqlimport\u00a0command in\u00a0Linux. mysqldump\u00a0is a command-line client program, it is used to dump local or remote\u00a0MySQL\u00a0database or collection of databases for backup into a single flat file. How &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/02\/mysql-backup-and-restore-commands-for-database-administration\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MySQL Backup and Restore Commands for Database Administration&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13414","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13414"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13414\/revisions"}],"predecessor-version":[{"id":13415,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13414\/revisions\/13415"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}