开发者

How to force MySQL out of TRADITIONAL mode?

开发者 https://www.devze.com 2023-01-28 02:06 出处:网络
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\"

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 stron开发者_StackOverflow中文版ger, sort of "nuclear" option to fix this?


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.


To allow invalid dates, you need:

SET sql_mode = 'ALLOW_INVALID_DATES';

But you'd better fix your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号