{"id":653,"date":"2021-11-14T22:39:42","date_gmt":"2021-11-15T03:39:42","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=653"},"modified":"2024-02-08T08:41:18","modified_gmt":"2024-02-08T13:41:18","slug":"backing-up-mysql-databases-using-mysqldump","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/backing-up-mysql-databases-using-mysqldump\/","title":{"rendered":"Backing up MySQL databases using mysqldump"},"content":{"rendered":"\n<p>mysqldump command is used to backup up MySQL databases. mysqldump has the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u &#91;login] -p &#91;pass] &#91;dbname] &gt; &#91;backup.sql]\n<\/code><\/pre>\n\n\n\n<p>where [backup.sql] is the file to which the backup should be written.<\/p>\n\n\n\n<p><strong>Backing up specific tables<\/strong>&nbsp;By default, mysqldump would backup the entire database. If you need to backup only specific tables, list the tables as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u &#91;user] -p &#91;pass] &#91;dbname] &#91;tables] &gt; &#91;backup.sql]    \n<\/code><\/pre>\n\n\n\n<p>where [tables] is the list of tables you wish to back up.<\/p>\n\n\n\n<p><strong>Backing up all databases<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump --all-databases -u &#91;user] -p &#91;pass] &gt; &#91;backup.sql]    \n<\/code><\/pre>\n\n\n\n<p><strong>Backing up specific tables<\/strong>&nbsp;By default, mysqldump would backup the entire database. If you need to backup only specific tables, list the tables as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u &#91;user] -p &#91;pass] --databases &#91;dbnames] &gt; &#91;backup.sql]    \n<\/code><\/pre>\n\n\n\n<p>where [dbnames] is the list of databases you wish to back up.<\/p>\n\n\n\n<p><strong>Adding drop table commands<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump --add-drop-table -u &#91;login] -p &#91;pass] &#91;dbname] &gt; &#91;backup.sql]    \n<\/code><\/pre>\n\n\n\n<p>Drop the table if it already exists.<\/p>\n\n\n\n<p><strong>Backup only the structure<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump --no-data -u &#91;login] -p &#91;pass] &#91;dbname] &gt; &#91;backup.sql]    \n<\/code><\/pre>\n\n\n\n<p><strong>Writing a backup shell script<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\ndt=`date -I`\nmysqldump --all-databases | gzip &gt; backup-$dt.sql.gz<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>mysqldump command is used to backup up MySQL databases. mysqldump has the following format: where [backup.sql] is the file to which the backup should be written. Backing up specific tables&nbsp;By default, mysqldump would backup the entire database. If you need to backup only specific tables, list the tables as follows: where [tables] is the list [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,204],"tags":[],"class_list":["post-653","post","type-post","status-publish","format-standard","hentry","category-database","category-mysql"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=653"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/653\/revisions"}],"predecessor-version":[{"id":654,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/653\/revisions\/654"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}