I am newbie to Laravel 5 and 6. I have very specific question, solution was developed using laravel and MSSQL server as DB server. Now I want to change Database from MSSQL to MySQL, is there any automated way to achieve this ? Or how cumbersome is this process and what will be the step to achieve this?
Thanks & regards
CodePudding user response:
If with solution, you mean to migrate the logic and don't care about data.
- Simply create a new database in MySQL.
- Config
.env
file to use said db, for example:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=my-db-name-here DB_USERNAME=root DB_PASSWORD=
- Clear all cache, like:
php artisan config:clear --no-ansi php artisan cache:clear --no-ansi composer dump-autoload php artisan view:clear --no-ansi php artisan route:clear --no-ansi
- Test if the routes work, like:
php artisan route:list --no-ansi
- At last, recreate DB structure, like:
php artisan migrate --no-ansi
If your project is new, there are no seed, else another useful command would be:
php artisan db:seed --no-ansi
But if Data are required:
The steps are basically the same as above;
But either you need to follow instructions at: https://www.thegeekstuff.com/2014/03/mssql-to-mysql/
Which shows how to directly copy data from source DB to destination.
Or you will need to:
- Export your MS SQL Server as SQL-file (or zip).
- Find/pick a tool, which converts SQL-files from "MS SQL Server" syntax/format to "MySQL" format.
- Import resulting SQL-file in MySQL.
CodePudding user response:
Simply create a new database in MySQL. Config .env file to use this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my-db-name-here
DB_USERNAME=root
DB_PASSWORD=
Clear all cache, like:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear
recreate DB structure:
php artisan migrate