rooskie's avatar

Supported versions of MySQL on Laravel 10

I've recently moved my website code to a new hosting company. The website works nearly identically except for a few areas where I'm getting unpredictable behavior.

I discovered that the new server had MySQL 8 installed by default where the previous server was using version 5.7.

The Laravel documentation states that "Laravel [10] provides first-party support for five databases" It lists MySQL 5.7+ as one of these. Does the plus symbol mean that both v5.7 and v8 are compatible out of the box? Is there any configuring that must be done to migrate from 5.7 to 8?

This thread from three years ago seems to suggest that MySQL 8 has been compatible since Laravel 8, but it didn't give my any clues about migrating (No issues with database migrations yet).

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, Laravel 10 supports both MySQL 5.7 and MySQL 8 out of the box. However, there may be some configuration changes required when migrating from MySQL 5.7 to MySQL 8. One potential issue is that MySQL 8 has stricter SQL mode settings by default, which may cause some queries to fail. To resolve this, you can update the SQL mode settings in your MySQL configuration file or in your Laravel database configuration.

Here's an example of how to update the SQL mode in Laravel's database configuration file:

// config/database.php

return [
    // ...
    'mysql' => [
        // ...
        'strict' => false,
        'modes' => [
            // Disable ONLY_FULL_GROUP_BY
            'NO_ZERO_IN_DATE',
            'NO_ZERO_DATE',
            'ALLOW_INVALID_DATES',
            'ERROR_FOR_DIVISION_BY_ZERO',
            'NO_ENGINE_SUBSTITUTION',
        ],
    ],
    // ...
];

In this example, we're disabling the ONLY_FULL_GROUP_BY mode and enabling other modes that are required for compatibility with MySQL 8.

If you're still experiencing unpredictable behavior after updating the SQL mode, you may need to review your code and database schema to ensure that they're compatible with MySQL 8.

Please or to participate in this conversation.