sql模式設(shè)置引起的問題解決辦法
1 報(bào)錯(cuò)類似如下
數(shù)據(jù)庫錯(cuò)誤: Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
The error may exist in URL [jar:file:/usr/local/xxxxx.jar!/BOOT-INF/lib/summer-system-4.6.0.jar!/mapper/system/SuOrgProgramMapper.xml]
The error may involve com.ruoyi.system.mapper.SuOrgProgramMapper.selectSuOrgProgramList-Inline
The error occurred while setting parameters
SQL: select sop.*,so.org_name as orgName,sa.activity_name as activityName,sa.activity_name_en as activityNameEN, ss.student_id as matchedStudentId,ss.name as matchedStudentName, su.login_name as email, su.real_name AS firstName, su.nickname as nickname from su_org_program sop inner join su_activity sa on sop.activity_id=sa.activity_id inner join su_org so on so.org_id = sop.org_id left JOIN sys_user su ON sop.main_teacher_id = su.sub left join (select * from su_student_program where is_matched=1) ssp on ssp.org_program_id= sop.org_program_id left JOIN su_student ss on ssp.student_id=ss.student_id WHERE sop.org_id = ? GROUP BY sop.org_program_id
Cause: java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\n; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression 39 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.ss.student_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
2 解決辦法
2.1 查看全局sql模式
使用如下m命令:
select @@global.sql_mode;
如下:
mysql> select @@global.sql_mode; +-------------------------------------------------------------------------------------------------------------------------------------------+ | @@global.sql_mode | +-------------------------------------------------------------------------------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +-------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
2.2 設(shè)置全局sql模式
使用如下命令:
SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
如下:
ysql> SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
2.3 查看當(dāng)前sql模式
使用如下命令:
select @@sql_mode;
如下:
mysql> select @@sql_mode; +------------------------------------------------------------------------------------------------------------------------+ | @@sql_mode | +------------------------------------------------------------------------------------------------------------------------+ | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
2.4 設(shè)置當(dāng)前sql模式
使用如下命令:
set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
如下:
mysql> set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
3 永久生效的解決辦法
3.1 找到my.cnf文件
可以使用如下命令查找,一般在 /etc/下或者 /etc/mysql/ 目錄下
find /etc/ -name my.cnf
3.2 編輯my.cnf文件
vi /etc/mysql/my.cnf
然后增加以下內(nèi)容:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
3.3 重啟數(shù)據(jù)庫服務(wù)
systemctl restart mysqld
到此這篇關(guān)于sql模式設(shè)置引起的問題解決辦法的文章就介紹到這了,更多相關(guān)sql模式設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MYSQL row_number()與over()函數(shù)用法詳解
這篇文章主要介紹了MYSQL row_number()與over()函數(shù)用法詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08mysql慢查詢?nèi)罩据嗈D(zhuǎn)_MySQL慢查詢?nèi)罩緦?shí)操
這篇文章主要介紹了mysql慢查詢?nèi)罩据嗈D(zhuǎn)_MySQL慢查詢?nèi)罩緦?shí)操,文章圍繞主題展開詳細(xì)的內(nèi)容戒殺,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09深度解析MySQL啟動(dòng)時(shí)報(bào)“The server quit without updating PID file”錯(cuò)誤的原
這篇文章主要介紹了MySQL啟動(dòng)時(shí)報(bào)“The server quit without updating PID file”錯(cuò)誤的原因,需要的朋友可以參考下2017-05-05Mysql Binlog快速遍歷搜索記錄及binlog數(shù)據(jù)查看的方法
這篇文章主要介紹了Mysql Binlog快速遍歷搜索記錄及binlog數(shù)據(jù)查看的方法的相關(guān)資料,需要的朋友可以參考下2016-01-01MySQL串行化隔離級(jí)別(間隙鎖實(shí)現(xiàn))
本文主要介紹了MySQL串行化隔離級(jí)別(間隙鎖實(shí)現(xiàn)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06