如何强制MySQL退出传统模式?

发布于 2024-10-05 02:33:11 字数 298 浏览 0 评论 0原文

我有一个旧应用程序,从 MySQL 5.0 升级到 5.1 后开始出现故障。

一些研究表明这是由于“严格模式”导致插入某些类型的“无效”值,而这些值之前只是自动转换为合理的值。

我尝试了 SET @@SESSION.sql_mode = ''SET @@GLOBAL.sql_mode = '' 但仍然收到错误。

还尝试在 my.ini 中注释掉 sql_mode

是否有更强大的“核”选项来解决这个问题?

I have an old application that started failing after an upgrade from MySQL 5.0 to 5.1.

A bit of research indicated this is due to "strict mode" which prevents inserting certain types of "invalid" values which previously were just automatically converted to something reasonable.

I tried SET @@SESSION.sql_mode = '' and SET @@GLOBAL.sql_mode = '' but I still get the error.

Also tried commenting out sql_mode in the my.ini.

Is there a stronger, sort of "nuclear" option to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃安静 2024-10-12 02:33:11

在我的应用程序中,我通常通过在每个新连接上发出命令来确保 MySQL 连接使用传统模式

SET SESSION sql_mode = 'ANSI_QUOTES,TRADITIONAL'

。我认为如果您只是

SET SESSION sql_mode = ''

在每个新连接上发出问题,您就会解决问题。

您应该能够通过发出命令来更改新连接的默认 SQL 模式,

SET GLOBAL sql_mode = ''

但您必须使用具有足够权限的帐户来执行此操作,否则它将无法工作。

我认为,如果您想确保应用程序运行特定的 SQL 模式,最可靠的方法是为每个新连接设置它。

In my application I usually make sure that the MySQL connection is using traditional mode by issuing

SET SESSION sql_mode = 'ANSI_QUOTES,TRADITIONAL'

on each new connection. I presume that if you just issue

SET SESSION sql_mode = ''

on each new connection, you will have solved the problem.

You should be able to change the default SQL mode for new connections by issuing

SET GLOBAL sql_mode = ''

but you must use an account with sufficient privileges to do this or it won't work.

I think that if you want to make sure a particular SQL mode is in operation for your application, the most robust way to do so is to set it for each and every new connection.

北斗星光 2024-10-12 02:33:11

要允许无效日期,您需要:

SET sql_mode = 'ALLOW_INVALID_DATES';

但您最好修复您的应用程序。

To allow invalid dates, you need:

SET sql_mode = 'ALLOW_INVALID_DATES';

But you'd better fix your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文