How to fix SQLSTATE: Syntax error or access violation: 1055
We have recently set up and configured Mautic on one of our Ubuntu 20.04.2 LTS systems. While accessing the email reports section, we noticed that the page was not loading. While troubleshooting the issue and checking the error logs we noticed the following mentioned MySQL error1 .
SQLSTATE: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
As per the MySQL documentation 2 , having the only full group by mode in the SQL mode will reject queries which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on GROUP BY columns.
We could make the required changes in the query to solve the SQL mode. In our case, we bypassed the error using the second option.
Run the following MySQL command to log in as MySQL root user and view the existing values
sudo mysql -u root -p mysql> SELECT @@global.sql_mode;
Keep a backup of the existing values to make sure that we will be able to revert the changes if required. Now run the below command to make the changes required.
mysql> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Another possible solution is to make the changes directly on the my.cnf file. You can find my.cnf file using the following command. In our case, We have followed the second option of adding the entries to the ‘my.cnf’ file.
find / -name my.cnf
In our case, the path is ‘/etc/mysql/my.cnf’. Now modify the my.cnf file to add the required sql_mode in the mysqld block. For example,
Restart the MySQL service to have the changes reflected.
sudo systemctl restart mysql