简体   繁体   English

如何使用多个值设置 Amazon RDS SQL_MODE

[英]How to set Amazon RDS SQL_MODE with multiple values

MySQL allows parameter SQL_MODE to be set to multiple values in the my.cnf file. MySQL 允许在 my.cnf 文件中将参数 SQL_MODE 设置为多个值。 How can I do the same on Amazon RDS?我如何在 Amazon RDS 上做同样的事情?

UPDATE: This problem has been fixed...see below.更新:此问题已修复...见下文。

Helpfully it looks like Amazon have fixed this as of May 24th 2016看起来亚马逊已经在 2016 年 5 月 24 日解决了这个问题

The sql_mode parameter can now be set to a list of values for all MySQL and MariaDB versions. sql_mode参数现在可以设置为所有 MySQL 和 MariaDB 版本的值列表。 The list of values should be correct in all regions as well.所有地区的值列表也应该是正确的。

https://forums.aws.amazon.com/thread.jspa?threadID=232266 https://forums.aws.amazon.com/thread.jspa?threadID=232266

MySQL allows parameter SQL_MODE to be set to multiple values in the my.cnf file. MySQL 允许在 my.cnf 文件中将参数 SQL_MODE 设置为多个值。 However, Amazon RDS allows only one value, whether you use their browser-based console or their CLI tools.但是,Amazon RDS 只允许一个值,无论您是使用他们基于浏览器的控制台还是他们的 CLI 工具。

I have found a (perhaps not perfect) solution to the problem of not being able to set SQL_MODE to multiple values.对于无法将 SQL_MODE 设置为多个值的问题,我找到了一个(也许不是完美的)解决方案。 In my procedure below, I show what my settings are.在下面的程序中,我展示了我的设置。 You may choose whatever values you think are pertinent to your environment.您可以选择您认为与您的环境相关的任何值。

1) In your parm group, set SQL_MODE = TRADITIONAL (or which ever one value is your highest priority) 1) 在您的 parm 组中,设置 SQL_MODE = TRADITIONAL(或哪个值是您的最高优先级)

2) In your parm group, set init_connect to: SET SESSION sql_mode = 'TRADITIONAL,IGNORE_SPACE,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY' 2) 在您的 parm 组中,将 init_connect 设置为:SET SESSION sql_mode = 'TRADITIONAL,IGNORE_SPACE,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY'

Now when a client logs into the database, their session SQL_MODE should be set to all values passed in by the init_connect string.现在,当客户端登录数据库时,其会话 SQL_MODE 应设置为 init_connect 字符串传入的所有值。 In my case, this equates to: IGNORE_SPACE, ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, TRADITIONAL, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION就我而言,这相当于:IGNORE_SPACE、ONLY_FULL_GROUP_BY、STRICT_TRANS_TABLES、STRICT_ALL_TABLES、NO_ZERO_IN_DATE、NO_ZERO_DATE、ERROR_FOR_DIVISION_BY_ZERO、TRADITIONAL、NO_AUTO_CITUREATE

Caveat: Editing the init_connect value after setting it involved cut-n-paste.警告:设置后编辑 init_connect 值涉及剪切粘贴。 However, I found that trying to delete an init_connect value after setting it is a big hassle, so be careful in working with it.但是,我发现在设置 init_connect 值后尝试删除它是一件很麻烦的事情,所以在使用它时要小心。 The hassle?麻烦吗? To delete an init_connect value after setting it required that I create a new parm group from scratch, set all values except init_connect to what the original parm group had, delete the original parm group, then rename the new group with the old name.要在设置后删除 init_connect 值需要我从头开始创建一个新的 parm 组,将除 init_connect 之外的所有值设置为原始 parm 组所具有的值,删除原始 parm 组,然后使用旧名称重命名新组。 This was true with both Firefox and Chrome. Firefox 和 Chrome 都是如此。 I also could not delete the value using the CLI tool (aws rds modify-db-parameter-group).我也无法使用 CLI 工具(aws rds modify-db-parameter-group)删除该值。

Although not really part of this post, if anyone responds with how to delete/reset/null-out init_connect without the kind of hassle I describe above, that would be great.虽然不是这篇文章的真正组成部分,但如果有人回答如何删除/重置/空出 init_connect 而没有我上面描述的那种麻烦,那就太好了。

UPDATE 1:更新1:

Never mind.没关系。 I have discovered that an init_connect setting (on RDS) will NOT survive a database reboot.我发现 init_connect 设置(在 RDS 上)不会在数据库重启后继续存在。 Therefore, the solution I offered above does not work.因此,我上面提供的解决方案不起作用。

Also, since one cannot remove (delete) an init_connect setting through the console (why not?), one can remove it by using the aws rds reset-db-parameter-group CLI command rather than rebuilding the whole parameter group like I described before.此外,由于无法通过控制台删除(删除)init_connect 设置(为什么不呢?),因此可以使用aws rds reset-db-parameter-group CLI 命令将其删除,而不是像我之前描述的那样重建整个参数组.

I am VERY disappointed that Amazon RDS:我对 Amazon RDS 感到非常失望:

  • Does not allow multiple SQL_MODE values.不允许多个 SQL_MODE 值。
  • Does not allow us to delete an init_connect setting through the console.不允许我们通过控制台删除 init_connect 设置。

UPDATE 2:更新 2:

Per Ross Scrivener's response, I tested setting multiple SQL_MODE values through the AWS console.根据 Ross Scrivener 的回复,我测试了通过 AWS 控制台设置多个 SQL_MODE 值。 I used the values 'TRADITIONAL,IGNORE_SPACE,ONLY_FULL_GROUP_BY' (no spaces).我使用了值 'TRADITIONAL,IGNORE_SPACE,ONLY_FULL_GROUP_BY'(无空格)。 I then rebooted the server twice, and everything seemed to have held.然后我重新启动了服务器两次,一切似乎都保持不变。

Thank you Amazon for fixing this, and thank you Ross Scrivener for pointing out the AWS change.感谢 Amazon 解决了这个问题,感谢 Ross Scrivener 指出 AWS 的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM