5

I'm working on a project, but always have to switch between 2 computers. I need to sync source code and database between 2 computers, so I can do my job on computer 1 at the morning, then continue the job on computer 2 at the evening.

To sync source code, I use git with pull/push action, but it's harder to sync database. My idea is use dropbox and some folders syncing software to auto sync between mysql/data/mydb folder and dropbox folder on computer 1, then auto sync between dropbox folder and mysql/data/mydb folder on computer 2. But then I realized that databases can't be copied that way, it just created an empty database.

Is there a way to move database via copying files, or another way to have my project done on 2 computers?

Mee
  • 223
  • 4
  • 13
  • possible duplicate of [git repository sync between computers, when moving around?](http://stackoverflow.com/questions/4948190/git-repository-sync-between-computers-when-moving-around) –  Dec 12 '14 at 04:47
  • Why not just set up a remote MySQL database somewhere? You could also use SQLite for file-based databases if your project has a quick way to switch to that (e.g. Symfony) – sjagr Dec 12 '14 at 04:50
  • @sjagr I tried but that'd make the local site run too slowly – Mee Dec 12 '14 at 04:52
  • @HoboSapiens but I want to move my database around, git can't do it. I don't want to export/import my db everytime there is a change. – Mee Dec 12 '14 at 04:54
  • You tried both? I mean you could do a master-slave replication but that wouldn't be too fun. How about two `bat` scripts that does a `mysqldump` and vice-versa before you git push/pull? – sjagr Dec 12 '14 at 04:54
  • This might be a fine time to use [git-hooks](http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) – Omni5cience Dec 12 '14 at 04:55
  • @sjagr My db is about 500mb, that'd take a long time to export/import. And sorry I only saw your first suggestion, my knowledge have no idea about master-slave database, I will learn more about that, thank you. – Mee Dec 12 '14 at 05:00
  • @user76757 Not a problem, and is SQLite a no-go? If your project has database drivers that could work for you. Although with a 500mb database size the speeds probably won't be any better than a remote MySQL database. – sjagr Dec 12 '14 at 05:01
  • @sjagr My project is a vBulletin forum, I don't really know if it works with SQLite, but I will give it a try, thank you. – Mee Dec 12 '14 at 05:05
  • Doesn't shutting down the MySQL server save it's state to disk? I'll bet it really doesn't like having Dropbox mess with its data while it's running, but that doesn't mean you can't use it to sync the data. You could try a script to shutdown the server and copy the data to dropbox and another matching script to copy the data out of dropbox and start the server. This would probably only work if both instances of the MySQL server are running the same version. – Omni5cience Dec 12 '14 at 05:08

2 Answers2

2

Use portable XAMPP (download from here)

You can install the server inside a portable hard drive or pen drive and then run the server from there.

Sampath Liyanage
  • 4,776
  • 2
  • 28
  • 40
  • That's simple but a good idea. That way I will put the whole xampp folder into git and just pull/push to sync both source code and database. But I'm not sure if it really work, I must test to make sure before make your answer accepted. Thanks a lot! – Mee Dec 12 '14 at 06:50
  • Hi, sorry for late reply. I tried putting whole portable xampp folder in git, at first it doesn't work as pulled xampp can't be run on the other computer, but with some tricks, it worked now. – Mee Dec 27 '14 at 04:30
0

My suggestion is use git version control to sync your code. And for database use common database and while connection connect db with IP of another computer.