Laravel 11: How to Change Default SQLite to MySQL

Laravel 11: How to Change Default SQLite to MySQL

Laravel 11: How to Change the Default SQLite to MySQL

In Laravel 11, SQLite is set as the default database for the local environment. However, if you prefer to use MySQL, you can easily change the configuration.

Using Laravel Installer

When you create a new Laravel project using Laravel Installer (version 5.1 or later), you have the option to choose the database your application will use. If you select MySQL, the installer automatically changes the DB_CONNECTION environment value to mysql and sets the other relevant database parameters.

Default SQLite Configuration

If you don't use the Laravel Installer, the default database configuration will be SQLite. In this case, the the .env file will have the DB_CONNECTION set to sqlite, with the MySQL-related parameters commented out, like this:

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

Manually Switching to MySQL

If your project is using the default SQLite setup and you want to switch to MySQL, you’ll need to modify the .env file manually:

  1. Set the DB_CONNECTION to mysql.

  2. Uncomment the MySQL-related parameters and provide the appropriate values for your database configuration.

Your the .env file should look like this:

// ... DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password // ...

Once you've made these changes, your Laravel application will be configured to use MySQL instead of SQLite.

Souy Soeng

Souy Soeng

Hi there šŸ‘‹, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
šŸ‘Æ I’m looking to collaborate on open-source PHP & JavaScript projects
šŸ’¬ Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close