Fix MySQL Error 1055: Expression #1 of SELECT list is not in GROUP BY clause
You just moved your website to a new server (perhaps after following my CentOS 7 to AlmaLinux 9 Migration Guide), and suddenly your dashboard reports stop working. The error log throws this scary message:
Error 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column...
This happens because modern MySQL (5.7 and 8.0+) enables Strict Mode by default using a flag called ONLY_FULL_GROUP_BY. While this is good for data integrity, it breaks many legacy applications (like older Laravel or CodeIgniter apps) that were written with "lazy" SQL logic.
How to Check Your Current Mode
Before changing anything, let's confirm this is the issue. Run this query in your PHPMyAdmin or Terminal:
SELECT @@GLOBAL.sql_mode;
If you see ONLY_FULL_GROUP_BY in the result string, that is your culprit.
Solution 1: The "Lazy" Fix (Disable Strict Mode)
If you cannot rewrite the legacy code right now, you can tell MySQL to chill out and behave like the old version 5.6. Here is how to do it in aaPanel:
- Go to App Store > Find MySQL.
- Click Settings > Configuration.
- Find the line starting with
sql-mode=. - Replace it with this line (we removed the strict flag):
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
Don't forget to Restart MySQL from the Service tab for changes to take effect.
Solution 2: The "Framework" Fix (Laravel)
If you are using Laravel, you don't need to touch the server config. You can handle this in your config/database.php file.
Find the mysql array connection settings and change strict to false:
'mysql' => [
'driver' => 'mysql',
// ... other settings
'strict' => false, // This disables all strict modes
],
Conclusion
While disabling strict mode gets your site back online quickly, the best long-term solution is to fix your SQL queries to be standard-compliant. If you struggle to rewrite complex queries, try using my Text-to-SQL AI Strategy to generate the correct syntax for you.
Author: Marg | Daily Innovate Tech
Post a Comment for "Fix MySQL Error 1055: Expression #1 of SELECT list is not in GROUP BY clause"