Categories
Linux PHP

MySQL 5.7 incompatibility – sql_mode=only_full_group_by

If you update mysql to 5.7 you will face this error:

Database_Exception [ 1055 ]: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column XXX which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

This is because MySQL changed in 5.7 and ONLY_FULL_GROUP_BY is not enabled by default.
http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_only_full_group_by

If you use Kohana a quick fix will be to edit your /config/database.php

 array(
        'type'       => 'mysqli',
        'connection' => array(
            'hostname'   => 'localhost',
            'username'   => 'root',
            'password'   => '',
            'persistent' => FALSE,
            'database'   => 'somedatabase',
            'variables'  => array('sql_mode'=>'')
            ),
        'table_prefix' => 't_',
        'charset'      => 'utf8',
        'profiling'    => (Kohana::$environment===Kohana::DEVELOPMENT)? TRUE:FALSE,
     ),
);

I have added

'variables' => array('sql_mode'=>'')

If you are not using kohana a global way will be to edit /etc/mysql/my.cnf

[mysqld]
sql-mode="

Then restart the service

service mysql restart