Database sync or migration tool [closed]

ぐ巨炮叔叔 提交于 2019-12-03 12:25:11

问题


It is really a pain keeping production and development databases in sync manually.

Is there any tool that allows one to keep the two databases in sync? Something like the amazing Laravel framework's migrations thing?

I am using MySQL and PHP. I searched here and there but wasn't able to spot the right tool for the job.


回答1:


You should definitely have a look at phinx. Here's an example of a complex database migration step I performed using MySQL and PHP: https://coderwall.com/p/v3qg2q




回答2:


If I am not wrong you need a tool to create database version control to keep track of schema changes. You may use Cygnite Migration commands. It is simple to use and make your job easier.

For your reference-

Migration & Seeding Video Tutorial

Database migration tool




回答3:


Check out Schematic, It's designed to work with schema files in YAML or JSON, and it can be installed globally:

http://andrefigueira.github.io/Schematic/

And it's designed to be committed with your VCS so your database versions are stored with your project commits.




回答4:


It's not clear exactly what you want ...

  • one way from prod to dev?
  • data or ddl or both?

take a look at this thread: How to synchronize development and production database




回答5:


Try to use rubyrep http://www.rubyrep.org/. It can continuously replicate between two databases.




回答6:


If you just want the two DBs to be identical, why not use MySQL replication with your production as the master and the dev server as the slave.

MySQL Replication Docs




回答7:


1 . make your remote or production database accept remote connection using a wild card or special Ip address ! through some sort of cpanel or config file !

2 . you can extend the db artisan command like "db:sync".

3 . command code (not tested yet) :

$db_local = Config::get('database.'.env('DB_CONNECTION', 'db_local')); 
$dump = "tmp.db";
exec("mysqldump --user={$db_local['username']} --password='{$db_local['password']}' --host={$db_local['host']} {$db_local['database']} --ignore-table={$db['database']}.some_table > $dump");
$db_remote = Config::get('database.'.env('DB_CONNECTION', 'db_remote')); 
exec("mysql --user={$db_remote['username']} --password='{$db_remote['password']}' --host={$db_remote['host']} {$db_remote['database']} < $dump");

I did no add any function check as usually it's intended to work.

You can for example instead of a command, add some automation using events, cron job, listeners ... there's many options, but the main logic part trick is : Defining environment variable names for your 2 db connections, and in the app config database.php, define your connections credentials etc, and finally make use of the exec, mysqldump & mysql.

Good luck



来源:https://stackoverflow.com/questions/13775160/database-sync-or-migration-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!