{"id":83,"date":"2007-09-05T14:55:52","date_gmt":"2007-09-05T21:55:52","guid":{"rendered":"http:\/\/historicalwebber.mossiso.com\/archives\/83"},"modified":"2007-09-05T14:55:52","modified_gmt":"2007-09-05T21:55:52","slug":"tabledump","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2007\/09\/05\/tabledump\/","title":{"rendered":"Tabledump"},"content":{"rendered":"<p>I had the need once again to dump only certain tables from a database, instead of all 100+ tables. This was where I had a database with about 5-8 wordpress installs. I wanted to backup all of the tables for only one install. There is a way with mysqldump to do this, by listing out all of the tables you want to dump.  So I just wrote a bash script to take care of making the list of tables to dump.<\/p>\n<p>It has an array of database table names (without the common prefix) in the script. Then it prompts for the mysql user, database, and prefix.  It could be changed to prompt for a file that contains a list or array of table names.<\/p>\n<p>Anyhow, here it is for anyone&#8217;s use:<\/p>\n<p>[code lang=&#8221;Bash&#8221;]<br \/>\n#!\/bin\/bash<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;#<br \/>\n#           Ammon Shepherd                #<br \/>\n#              09.05.07                   #<br \/>\n#  Dump a database with only the tables   #<br \/>\n#   containing the prefix given.          #<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;#<\/p>\n<p>echo &#8220;This will dump just the tables with the specified prefix from the specified database.&#8221;<\/p>\n<p>echo -n &#8220;Enter the database name: &#8221;<br \/>\nread dbase<\/p>\n<p>echo -n &#8220;Enter the table prefix: &#8221;<br \/>\nread prefix<\/p>\n<p>echo -n &#8220;The mysql user: &#8221;<br \/>\nread sqluser<br \/>\necho -n &#8220;The mysql pass: &#8221;<br \/>\nread -s sqlpass<\/p>\n<p># Get list of tables with the desired prefix<br \/>\nlist=( $(mysql -u$sqluser -p$sqlpass $dbase &#8211;raw &#8211;silent &#8211;silent &#8211;execute=&#8221;SHOW TABLES;&#8221;) )<\/p>\n<p>for tablename in ${list[@]}<br \/>\ndo<br \/>\n    if [[ &#8220;$tablename&#8221; =~ $prefix ]]; then<br \/>\n        tablelist+=&#8221;$tablename &#8221;<br \/>\n    fi<br \/>\ndone<\/p>\n<p>`mysqldump -u$sqluser -p$sqlpass &#8211;opt $dbase $tablelist > $dbase.$prefix.bak.sql`<\/p>\n<p>echo<\/p>\n<p>exit 0<\/p>\n<p>[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had the need once again to dump only certain tables from a database, instead of all 100+ tables. This was where I had a database with about 5-8 wordpress installs. I wanted to backup all of the tables for only one install. There is a way with mysqldump to do this, by listing out &hellip; <a href=\"https:\/\/mossiso.com\/2007\/09\/05\/tabledump\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Tabledump<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[14],"tags":[23,63],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-computer-history","tag-bash-code","tag-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-1l","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/83"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}