Laravel 11: How to Change Default SQLite to MySQL

Laravel 11: How to Change Default SQLite to MySQL

 Laravel 11: How to Change Default SQLite to MySQL

Laravel 11 uses SQLite as the default database for the local environment. Let's see how we can change it to MySQL.


When creating a new Laravel project using Laravel Installer, starting with Installer version 5.1, you can choose which database your application will use.

After choosing MySQL, the installer will change the DB_CONNECTION env value to mysql and set DB values.

But if you don't use such a Laravel Installer, the default will be SQLite, with all the other DB parameters commented out in the .env file:

.env:

// ...
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
// ...

If that is your case and you want to change the database driver to MySQL, you must set the env values manually.

First, you must set the DB_CONNECTION to mysql. Then, uncomment the DB values and put the correct values for your settings. The env values should look similar:

.env:

// ...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
// ...
Reactions

Post a Comment

0 Comments

close