Blog Detail

28

Jul
Now Sync Remote Database to a Local Database in Laravel cover image

arrow_back Now Sync Remote Database to a Local Database in Laravel

Laravel DB Sync is an awesome package that let you sync a remote database to a local database in Laravel. The connection can be made over SSH or using a remote MySQL connection.

Install

You can install this package via composer:

composer require dcblogdev/laravel-db-sync

Config

You can publish the config file with:

php artisan vendor:publish --provider="Dcblogdev\DbSync\DbSyncServiceProvider" --tag="config"

.env

Set the remote database credentials in your .env file

When using SSH Add:

REMOTE_USE_SSH=true
REMOTE_SSH_PORT=22
REMOTE_SSH_USERNAME=
REMOTE_DATABASE_HOST=

REMOTE_DATABASE_USERNAME=
REMOTE_DATABASE_NAME=
REMOTE_DATABASE_PASSWORD=
REMOTE_DATABASE_IGNORE_TABLES=''

REMOTE_REMOVE_FILE_AFTER_IMPORT=true
REMOTE_IMPORT_FILE=true

For only MySQL remote connections:

REMOTE_DATABASE_HOST=
REMOTE_DATABASE_USERNAME=
REMOTE_DATABASE_NAME=
REMOTE_DATABASE_PASSWORD=
REMOTE_DATABASE_IGNORE_TABLES=''

REMOTE_REMOVE_FILE_AFTER_IMPORT=true
REMOTE_IMPORT_FILE=true

Set a comma seperate list of tables NOT to export in REMOTE_DATABASE_IGNORE_TABLES

To generate a SQL with a custom file name REMOTE_DEFAULT_FILE_NAME

Usage

To export a remote database to OVERRIDE your local database by running:

php artisan db:production-sync

Provide a filename for export on the fly by passing the option --filename, remember to provide .SQL

php artisan db:production-sync --filename=other.sql

Run the command without attempting to export:

php artisan db:production-sync --test

For more details, You can visit Github.

Note

If you are an enterprise and want to leverage Laravel for your next PHP-based web application, CRM Software, E-commerce application, SAAS application, or any custom web application development for your custom requirements, you must find an impeccable team with experience in the Laravel framework. So Codebrisk is here to help you with your tailored requirements regarding Laravel Development. For further assistance, Please feel free to send us an email at rizwan@codebrisk.com or get in touch with us, our business person will get back to you.

Published at : 28-07-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project