没有不值得去解决的问题,也没有不值得去学习的技术!

Temporarily Modify the sql_mode of a MySQL Container

Connect to MySQL inside the container by executing the command: mysql -h127.0.0.1 -uusername -ppassword.

1. SQL query error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘model.group_id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by. As shown in Figure 1

SQL query error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'model.group_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.
Figure 1

2. Connect to MySQL inside the container by executing the command: mysql -h127.0.0.1 -uusername -ppassword. As shown in Figure 2

Connect to MySQL inside the container by executing the command: mysql -h127.0.0.1 -uusername -ppassword.
Figure 2
Plaintext

root@mysql-696746d44d-mzc8d:/# mysql -h127.0.0.1 -umysql -phqy-webtv
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17304526
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

3. Temporarily modify the sql_mode of the MySQL container by executing the command: set global sql_mode=’STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’; . This is a temporary solution; once the MySQL container is upgraded or redeployed, the command must be executed again. The permanent solution should be to include this setting in the base image. As shown in Figure 3

Temporarily modify the sql_mode of the MySQL container by executing the command: set global sql_mode='STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; . This is a temporary solution; once the MySQL container is upgraded or redeployed, the command must be executed again. The permanent solution should be to include this setting in the base image.
Figure 3
Plaintext

mysql> set global sql_mode='STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)

mysql> 

4. The SQL query no longer reports errors, and the API response is normal. As shown in Figure 4

The SQL query no longer reports errors, and the API response is normal.
Figure 4

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系