{"id":1100,"date":"2018-09-01T10:23:45","date_gmt":"2018-09-01T15:23:45","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=1100"},"modified":"2018-09-01T10:34:06","modified_gmt":"2018-09-01T15:34:06","slug":"copy-database-or-table-from-one-mysql-server-to-another-clever-way","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=1100","title":{"rendered":"Copy database or table from one MySQL server to another, clever way."},"content":{"rendered":"<p>This simple bash script can copy database or a table from one remote server to another. Can be used as a backup, but also as a one way sync on a database or table.<\/p>\n<p><b>ssh -fNg&#8230;<\/b> &lt;- creates a permanent tunnel to the remote server on port 3307. So now from the local server you can access both local and remote MySQL.<\/p>\n<p><b>export MYSQL_PWD=&#8230;<\/b> &lt;- Helps hide password, as long as you make this script secure, the password it not accessible.<\/p>\n<p>Last one-liner does the rest, if you remove\u00a0&lt;DB_TABLE_NAME&gt; it will send the entire DB over to the remote, so be carefuller. But you already new that and have a backup, right?<\/p>\n<p><!--more--><\/p>\n<pre><code >#!\/usr\/bin\/bash<\/p>\n<p>ssh -fNg -L 3307:127.0.0.1:3306 &lt;USERNAME&gt;@&lt;REMORE_HOST&gt; -p 22<\/p>\n<p>export MYSQL_PWD=&lt;DB_PASSWORD&gt;<br \/>\nmysqldump --lock-tables=false -h localhost -u\u00a0&lt;DB_USERNAME&gt;\u00a0&lt;DB_NAME&gt;\u00a0&lt;DB_TABLE_NAME&gt; | mysql -P 3307 -h 127.0.0.1 -u\u00a0&lt;DB_USERNAME&gt;\u00a0--compress &lt;DB_NAME&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This simple bash script can copy database or a table from one remote server to another. Can be used as a backup, but also as a one way sync on a database or table. ssh -fNg&#8230; &lt;- creates a permanent tunnel to the remote server on port 3307. So now from the local server you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1100"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1100"}],"version-history":[{"count":12,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1100\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1100\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}