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, there is an option to 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 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=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravelDB_USERNAME=rootDB_PASSWORD= // ...
That did not work what else do we need to do? My Laravel Installer is v5.1.3 My Code: My Error message:
Your collation is different. Something with your
?
Why are you posting composer and env when the problem is on your db level?
This is a fresh install; the only thing I have done so far is setup this .env file and nothing else. Well running the install I did select the mysql for the database. You said that I needed to make the changes shown here; that is all I have done to this point this is why I am asking what else we have to do to get this to work?
I am using Composer v2.6.6 and Laravel Installer V5.1.3
Your db collation is wrong. It's the problem with your setup. Google your error message
I am using XAMPP v3.3.0 and according to it I am using utf8mb4_unicode_ci My system works just fine in Laravel 10.43.0 . The only thing I am doing deferent is installing Laravel 11 using the –dev to do so “Laravel new imrbkL11 –dev” If I leave off the –dev I get version 10.43.0 and It works Grate that Is why I still am wondering what else we have to do to get this to work!?
Where in Laravel 11 do I change the utf8mb4_0900_ai_ci back to the original utf8mb4_general_ci? Sense the config.php database file is not here? I tried to run the config:publish dashboard but I am getting an error doing that:
This is what you need to do.
That will show you all the available configs options select database (when you get to database, click on enter) and you should see a mesaage that it's successful. After that scroll to the mysql part if database.php, you'll see the collate part change it to
Everything should work perfectly.
Additional: when creating databse from terminal, i used this command
scores11 is the name of the database.
Had no problems with the default Laravel mysql settings.
started over and did the php artisan config:publish database option and then changed the 'collation' => 'utf8mb4_0900_ai_ci', TO
'collation' => 'utf8mb4_unicode_ci',
Everything is working just fine now.
Question can I remove the database.sqlite file or do I have to keep it there for the testing I am using Pest?
File can be deleted
File can be What? deleted or left!
Changed my driver from mysql to mariadb helped for me
If you are facing collation problem just upgrade your mysql version or if you don't want to, just navigate to config/database.php and in connections, change the collation for mysql from 'collation' => env('DB_COLLATION', 'utf8mb4_0900_ai_ci') to 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci').
Or just simply add 'DB_COLLATION=utf8mb4_unicode_ci' to your .env file.
I just installed the laravel 11 stable version. and i face same error. SQLSTATE[HY000]: General error: 1273 Unknown collation: 'utf8mb4_0900_ai_ci'
Database config is published when you install laravel 11 as I remember. Better way upgrade your mysql version to have laravels collation
yes, my bad the database.php config is aleady exisit with laravel 11. and i am using xammp any idea how to only upgrade the mysql part as far i check i use the latest xampp which is php 8