{"id":186,"date":"2014-04-13T15:52:59","date_gmt":"2014-04-13T19:52:59","guid":{"rendered":"http:\/\/www.lektrikpuke.com\/blog\/?p=186"},"modified":"2014-04-18T12:15:32","modified_gmt":"2014-04-18T16:15:32","slug":"syncing-mysql-database-between-a-mac-and-pc","status":"publish","type":"post","link":"https:\/\/lektrikpuke.com\/blog\/2014\/04\/13\/syncing-mysql-database-between-a-mac-and-pc\/","title":{"rendered":"Syncing MySQL Database Between A Mac And PC"},"content":{"rendered":"<p>I&#8217;ve been a long time Mac hater. Recently, though, I broke down and bought a Mac laptop.<\/p>\n<p>Being a geek on many levels, I immediately had to set it up as a development server environment. I won&#8217;t go into the full story, but suffice it to say, that after dabbling with MAMP, I decided to go back to the discrete installs. I mean, most of it is done already, anyway, and then you don&#8217;t have to deal with paying for MAMP Pro to get around starting your server on port 80. If you know what I mean, then I&#8217;ll assume you&#8217;ve been there.<\/p>\n<p>Although I originally wanted to put the database itself under revision control, talking to the guys in the IT department (and my boss), and doing research on the internet, I decided to go with something like <a href=\"http:\/\/code.tutsplus.com\/tutorials\/how-to-sync-a-local-remote-wordpress-blog-using-version-control--wp-22135\" target=\"_blank\">How to Sync A Local &amp; Remote WordPress Blog Using Version Control<\/a>.<\/p>\n<p>Okay, the general layout:<\/p>\n<ul>\n<li>Windows 7 PC development environment on desktop PC running MySQL &#8211; Master<\/li>\n<li>Mac OS X &#8211; Mavericks development environment on laptop also running MySQL &#8211; Slave<\/li>\n<li>Git &#8211; both systems<\/li>\n<\/ul>\n<p>The concept in a nutshell:<\/p>\n<ul>\n<li>PC &#8211; Run script that dumps your database to a folder that is under Git control<\/li>\n<li>PC &#8211; Script then adds and commits changes<\/li>\n<li>Mac &#8211; Run script that PULLS over the changes<\/li>\n<li>Mac &#8211; Script restores database<\/li>\n<\/ul>\n<p>This post assumes you have access and control of your systems, such that you can write, execute, and read where necessary. I will gloss over that stuff, if I touch it at all. Also, this is not a secure method. <strong>Use at your own risk.<\/strong> There are ways to get around the password in plain text issue, but that (among other things) is beyond the scope of this post.<\/p>\n<p>PC script:<br \/>\n<code><br \/>\nmysqldump -u USER -pPASSWORD DBNAME &gt; \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\"<br \/>\n\"C:\\Program Files (x86)\\Git\\cmd\\git\" add \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\"<br \/>\ngit commit \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\" -m \"auto commit\"<br \/>\n<\/code><\/p>\n<p>Let&#8217;s dissect this:<br \/>\n<code>mysqldump -u USER -pPASSWORD DBNAME &gt; \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\"<\/code><\/p>\n<ul>\n<li>mysqldump: command for dumping your database<\/li>\n<li>-u USER: the user that is running this command&#8211;root for instance<\/li>\n<li>-pPASSWORD: user password (preceeded with p for password)<\/li>\n<li>DBNAME: name of the database that you want to dump<\/li>\n<li>&gt;: Your sending the output to a file<\/li>\n<li>&#8220;C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql&#8221;: output file location and name (in quotes)<\/li>\n<\/ul>\n<p><code>\"C:\\Program Files (x86)\\Git\\cmd\\git\" add \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\"<\/code><\/p>\n<ul>\n<li>&#8220;C:\\Program Files (x86)\\Git\\cmd\\git&#8221;: location of git (just in case it&#8217;s not in your environment)<\/li>\n<li>add: command to add a file to the repository<\/li>\n<li>&#8220;C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql&#8221;: Location of file that&#8217;s being added. <strong>Should be the same as the location and file that you just dumped<\/strong><\/li>\n<\/ul>\n<p><code>git commit \"C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql\" -m \"auto commit\"<\/code><\/p>\n<ul>\n<li>git: I didn&#8217;t put the pathway to git here, so I must have it in my environment. If you don&#8217;t, specify the full pathway, like I did in the last code snippet<\/li>\n<li>commit: command to commit a file to the repository (put the file into the repo)<\/li>\n<li>&#8220;C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\dBExchange\\DBNAME.sql&#8221;: location and name of what you want to commit<\/li>\n<li>-m: message (to follow)<\/li>\n<li>&#8220;auto commit&#8221;: the message I chose to add&#8211;all commits by this script will have this message<\/li>\n<\/ul>\n<p>I saved the script in the dbExchange folder as export.bat (which makes it executable). I then sent a link to the desktop. That&#8217;s all there is to the PC script.<\/p>\n<p>Mac script:<br \/>\n<code><br \/>\n#!\/bin\/bash<br \/>\ncd \/Library\/WebServer\/Documents\/dBExchange<br \/>\ngit pull origin<br \/>\nmysql -u USER -pPASSWORD DBNAME &lt; \/Library\/WebServer\/Documents\/dBExchange\/DBNAME.sql<br \/>\n<\/code><\/p>\n<p>Dissection reveals:<br \/>\n<code>#!\/bin\/bash<\/code><\/p>\n<ul>\n<li>This lets your system know you&#8217;re running BASH script (script to be interpreted by BASH)<\/li>\n<li>This may be the system default, but it won&#8217;t hurt to put it in there<\/li>\n<\/ul>\n<p><code>cd \/Library\/WebServer\/Documents\/dBExchange<\/code><\/p>\n<ul>\n<li>Change to git (folder) directory<\/li>\n<\/ul>\n<p><code>git pull origin<\/code><\/p>\n<ul>\n<li>git: call to git. It&#8217;s in my environment, so no need to use pathway. Your settings may vary<\/li>\n<li>pull origin: Pull from remote (get data from master repo)<\/li>\n<\/ul>\n<p><code>mysql -u USER -pPASSWORD DBNAME &lt; \/Library\/WebServer\/Documents\/dBExchange\/DBNAME.sql<\/code><\/p>\n<ul>\n<li>mysql: Same idea as PC script, but instead of mysqldump you use mysql<\/li>\n<li>&lt;: Notice the director is in the opposite direction&#8211;less than as opposed to greater than<\/li>\n<li>\/Library\/WebServer\/Documents\/dBExchange\/DBNAME.sql: pathway and name of file to reload the database with<\/li>\n<li><strong>Note:<\/strong> This will completely overwrite this database. Be sure it&#8217;s what you want to do!<\/li>\n<\/ul>\n<p>I saved the script in the dbExchange folder as import.command (which makes it executable). I then made an alias to the command file and copied it to the desktop. That&#8217;s all there is to the Mac script.<\/p>\n<p><strong>Use:<\/strong> Double-click on the Windows desktop shortcut. Go to your Mac and make sure you are connected via network to the folder where the SQL file was dumped. Double-click on the alias file on the Mac desktop. It&#8217;s done! Note: The different processes, Git, mysqldump, mysql, may take time to finish. How much can vary and depends on database size, your computers, network speed, etc. Either way, be patient, it&#8217;ll be over before you know it!<\/p>\n<p>=)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been a long time Mac hater. Recently, though, I broke down and bought a Mac laptop. Being a geek on many levels, I immediately had to set it up as a development server environment. I won&#8217;t go into the &hellip; <a href=\"https:\/\/lektrikpuke.com\/blog\/2014\/04\/13\/syncing-mysql-database-between-a-mac-and-pc\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72,140,148],"tags":[203,5,136,89],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-computer-stuff","category-mac","category-mysql-computer-stuff","tag-mac","tag-mysql","tag-pc","tag-script"],"_links":{"self":[{"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":1,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions\/187"}],"wp:attachment":[{"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lektrikpuke.com\/blog\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}