There is a long long ago project. As the purchased Alibaba Cloud database expired and no one cares about it, the sad thing happened and the database was released. Nani, I was also a little confused. The manager asked if he could recover. Hey, I don't want to complain, but keep a guard against arrogance and rash ❤ think of a way to solve the problem.
I’m really lucky. Fortunately, there are not many users in that project, otherwise it is really going to be a lightning strike~ Fortunately, I have participated in that project before and there is a local DB.
Since I was not the owner of the previous operation and maintenance, and I did not know the specific database version, I installed an older version:5.7.26
select version() from dual;
=== > 5.7.26
There is a section of grouping sql. I remember that after the project was completed, there was no problem at all. I restored the database this time and found that it didn't work. emm~~
SELECT
t1.match_id AS matchId,
t2.event_id AS eventId,
t2.logo AS eventLogo,
t1.match_stauts AS matchStatus,
t5.status_name AS statusName,
t1.start_game_time AS startGameTime,
t1.start_ball_time AS startBallTime,
t1.flash_flg AS flashFlg,
t3.name_zh AS homeTeamName,
t3.logo AS homeTeamLogo,
t1.home_team_score AS homeTeamScore,
t4.name_zh AS visitTeamName,
t4.logo AS visitTeamLogo,
t1.visit_team_score AS visitTeamScore,
t2.name_zh AS eventName,
t2.short_name_zh AS eventShortName
FROM
app_leisu_matchs t1
LEFT JOIN app_leisu_events t2 ON t1.event_id = t2.event_id
LEFT JOIN app_leisu_teams t3 ON t1.home_team_id = t3.team_id
LEFT JOIN app_leisu_teams t4 ON t1.visit_team_id = t4.team_id
LEFT JOIN app_leisu_match_status t5 ON t1.match_stauts = t5.match_status
LEFT JOIN app_leisu_odds t6 ON t1.match_id = t6.match_id
WHERE
t1.match_stauts IN (1, 2, 3, 4, 5, 6, 7)
AND FROM_UNIXTIME(
t1.start_game_time,
'%Y-%m-%d'
) = DATE_FORMAT(NOW(), '%Y-%m-%d')
GROUP BY
t1.match_id
ORDER BY
FIELD(
t1.match_stauts,
2,
3,
4,
5,
6,
7,
1
),
t1.start_game_time ASC,
t1.start_ball_time ASC
LIMIT 0, 10
Error report exception:
[Err] 1055 - Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'qiuyoule.t5.status_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Error analysis:
In fact, it is very clear after the translation, that is, the field taken out by select does not belong to the condition of group by, which violates sql_mode =Is the configuration of only_full_group_by ~ Looking at the sql above, you will find that group by has only one t1.match_id, but there are so many fields in select, hahaha~ Nothing wrong with the report ~
Configure the mysql environment, I think it is related to the version of the database, Baidu checked it, it is indeed
In version 5.7 and above, the default is only_full_group_by

, That is, the select field can only be the field in the group by.
So, I guess, the default environment of this project was 5.6 before~ I want to cry~
Change sql_mode
Method one (data is invalid after restart):
directly take out only_full_group_by
set @@GLOBAL.sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
If it does not take effect, try restarting the next project~
Note: In this solution, if the database service is restarted, it will be restored to the default only_full_group_by! ! ! Pro test~
Method Two:
Modify the my.ini file
Under the [mysqlld] node,
append
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
Remember to restart the database service~~
Just remove only_full_group_by from the original sql_mode variable!
Scenario: The same product, different models, there are different prices, such as 1 mobile phone has 128G, 2,256g, 2500 yuan, but the product display page, the price shows 2,000 yuan, if it is a produ...
Database removing duplicate data, the data needs to be packed and one of them is displayed. The group by statement may be used. However, if MySQL is above 5.7 or more, when the group by is executed, i...
1055 - Expression #1 of SELECT list 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_m...
mysql5.7 + version is turned on by defaultonly_full_group_byMode,When you turn on this mode, the column must query conditions are grouped. The original group by statement will be reported this error. ...
On database 5.7, only_full_group_by mode will be enabled by default, but after enabling this mode, the original group by statement will report an error. Cause Analysis: For group by aggregation operat...
I wrote an sql when using mybits in the project: It was correct when tested on a machine, but it was wrong when it was put on the server: This matter caused an error because some versions of mysql5.7 ...
Solution: modify the mysql configuration file The local server can modify this Add under [mysqld] Then restart service mysql restart ...
Specific error: [Err] 1055-Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ’ which is not functionally depende...
Error scenario Today, I have a project that I just came down on my computer. When I log in to enter the home page, I reported a string of this is incompatible with sql_mode = only_full_group_by error,...
Report error message: Reporting error Mysql 5.7.5 and above function dependencies. If ONLY_FULL_GROUP_BY is enabled SQL Mode (By default), MySQL will refuse to select a list, the Having condition, or ...