Laravel School

Snippet Github Twitter

How to migrate SQL dump file in Laravel DB Seed

Thouhedul Islam
1 year ago


Normally we use db:seed in Laravel by faker data. However, today, I will show you how to migrate SQL dump file in Laravel DB Seeder.

Step 1

Run migration command-

php artisan migrate

Step 2

Download your dump file and paste into database/seeds/source folder.

- database
-- seeds
--- source
---- dump_file

Step 3

Go to database/seeds/DatabaseSeeder.php file and include the dump file to migrate into db inside the run() method.

ini_set('memory_limit', '-1');

\DB::unprepared(file_get_contents(__dir__ . '/source/dump_file'));

Note: You can use .sql file in the same way also. In that case, you just need to adjust the file extension.

Step 4

Finally, run the following command-

php artisan db:seed

It should populate data from your dump_file to your database now.


Hello. I’m Thouhedul Islam. Some people also know me as Suchi.

I am a Full-stack Developer. I love to play with PHP especially Laravel, JavaScript, MySql, and the latest web technology. Currently, I am working for GLEIF as my day time job.

At night I love to solve problems for the community. I love to be active at Laracasts.