mysql 5.7如何修改 sql_mode

2016-08-12 14:02:00
hainuo
原创 2090
摘要:mysql 5.7 如何修改 sql_mode
#起源因上一篇文章[only_full_group_by是什么鬼](https://blog.hainuo.info/blog/221.html) 修改 `mysql` 的 `sql_mode` 出错,本以为在 `my.cnf` 中加入了 `sql_mode=''`就可以了却发现问题仍然存在#排查刚才说了 `my.cnf` 中定义了 `sql_mode=''` 那么怎么查看生效没生效呢。简单 登陆终端或者进入`phpmyadmin`,这里以终端演示```shell$ mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.13-log MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]> select @@sql_mode;+-------------------------------------------------------------------------------------------------------------------------------------------+| @@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)MySQL [(none)]> quit```#修复经过查看源码 尤其是 `mysql.server` 的源码发现这里有些问题,就是它里面提到了一个叫做`my-default.cnf` 的文件,然后将里面的 `sql_mode` 注释掉 (在其前面加入'#'字符)ps:`my-default.cnf` 位置跟 `mysql.server` 相同为 `mysql` 安装目录的 `suppor-files` 目录
发表评论
玖 减 贰 =
评论通过审核后显示。