{"id":54962,"date":"2020-04-13T10:44:36","date_gmt":"2020-04-13T15:44:36","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/?p=54962"},"modified":"2020-04-23T15:05:36","modified_gmt":"2020-04-23T19:05:36","slug":"how-to-backup-mysql-database-on-command-line","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/","title":{"rendered":"How to Backup MySQL Database on Command Line"},"content":{"rendered":"\n<p>For all of your SQL backup needs, the <code>mysqldump<\/code> command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#howtobackupasingledatabaseonthecommandline\">How to backup a single database on the command line<\/a><\/li><li><a href=\"#howtobackupalldatabasesonthecommandline\">How to backup all databases on the command line<\/a><\/li><li><a href=\"#howtobackupalldatabasesonthecommandline\">How to backup a WordPress database on command Line<\/a><\/li><\/ul>\n\n\n\n<p>This makes it much easier to transfer databases to other servers as well as creating backups.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"howtobackupasingledatabaseonthecommandline\">How To Backup a Single Database On The Command Line<\/h2>\n\n\n\n<p>In order to backup a single database, you\u2019ll just need to run this statement at your command prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump > dump.sql<\/code><\/pre>\n\n\n\n<p>In this case, \u201cdump.sql\u201d is the backup file you want to generate. You can change that filename to whatever you want.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"howtobackupalldatabasesonthecommandline\">How To Backup All Databases on The Command Line<\/h2>\n\n\n\n<p>If you maintain multiple sites with multiple databases, you can also back them all up with one command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump --all-databases > dump.sql<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"howtobackupawordpressdatabaseoncommandline\">How To Backup a WordPress Database On Command Line<\/h2>\n\n\n\n<p>Using the command line is simply faster and more efficient. For example, with two commands, you can locate and backup a WordPress database.<\/p>\n\n\n\n<p>First, make sure you change directories into the root of the WordPress site (where the core files are located).<\/p>\n\n\n\n<p>Then drop this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dw(){ dr=\"${1-$PWD}\"; config=\"${dr%\/}\/wp-config.php\"; db=$(grep \"DB_NAME\" $config|cut -d\\' -f4); usr=$(grep \"DB_USER\" $config|cut -d\\' -f4); pw=$(grep \"DB_PASSWORD\" $config|cut -d\\' -f4); pre=$(grep \"table_prefix\" $config|cut -d\\' -f2);}; dw<\/code><\/pre>\n\n\n\n<p>Now the database name and user\/password information are stored in variables that will be used when you run the next command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -Q --add-drop-table --routines -h${host-localhost} -p\"$pw\" -u$usr $db<\/code><\/pre>\n\n\n\n<p>So with two commands you now have a backup of the WordPress database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database. How to backup a single database on the command line How to backup all databases on the command line How to backup a WordPress<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\"> Read More ><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4308],"tags":[],"class_list":["post-54962","post","type-post","status-publish","format-standard","hentry","category-linux"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Backup MySQL Database on Command Line | Linux SQL Commands<\/title>\n<meta name=\"description\" content=\"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the 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.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Backup MySQL Database on Command Line | Linux SQL Commands\" \/>\n<meta property=\"og:description\" content=\"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-13T15:44:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-23T19:05:36+00:00\" \/>\n<meta name=\"author\" content=\"Christopher Maiorana\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christopher Maiorana\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\"},\"author\":{\"name\":\"Christopher Maiorana\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\"},\"headline\":\"How to Backup MySQL Database on Command Line\",\"datePublished\":\"2020-04-13T15:44:36+00:00\",\"dateModified\":\"2020-04-23T19:05:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\"},\"wordCount\":250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\",\"name\":\"How to Backup MySQL Database on Command Line | Linux SQL Commands\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2020-04-13T15:44:36+00:00\",\"dateModified\":\"2020-04-23T19:05:36+00:00\",\"description\":\"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Backup MySQL Database on Command Line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\",\"name\":\"Christopher Maiorana\",\"description\":\"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/\"],\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Backup MySQL Database on Command Line | Linux SQL Commands","description":"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the 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.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/","og_locale":"en_US","og_type":"article","og_title":"How to Backup MySQL Database on Command Line | Linux SQL Commands","og_description":"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database.","og_url":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2020-04-13T15:44:36+00:00","article_modified_time":"2020-04-23T19:05:36+00:00","author":"Christopher Maiorana","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Christopher Maiorana","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/"},"author":{"name":"Christopher Maiorana","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f"},"headline":"How to Backup MySQL Database on Command Line","datePublished":"2020-04-13T15:44:36+00:00","dateModified":"2020-04-23T19:05:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/"},"wordCount":250,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/","url":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/","name":"How to Backup MySQL Database on Command Line | Linux SQL Commands","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2020-04-13T15:44:36+00:00","dateModified":"2020-04-23T19:05:36+00:00","description":"For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/how-to-backup-mysql-database-on-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Backup MySQL Database on Command Line"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f","name":"Christopher Maiorana","description":"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.","sameAs":["https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/"],"url":"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/54962","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=54962"}],"version-history":[{"count":6,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/54962\/revisions"}],"predecessor-version":[{"id":55149,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/54962\/revisions\/55149"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=54962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=54962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=54962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}