How can I make fatal errors of ALL mysql warnings?

早过忘川 提交于 2020-07-15 06:56:45

问题


Is there any way to promote all mysql warnings to fatal errors? I'd like to avoid any data truncation (including fractional parts).


回答1:


In some modes, MySQL raises warnings instead of the errors that are required by the SQL Standard.

You certainly want to raise an error when significant data is removed, but you probably don't want an error raised when a COUNT(colname) expression finds some rows with nulls in the column and ignores them for counting purposes (a Standard warning).

As MySQL becomes more conformant to the Standard, warnings that do not have data integrity implications may be added.

If using MySQL in a mode that more closely follows the SQL Standard is not enough, you could catch the unacceptable warnings in your application code and add appropriate compensating actions.




回答2:


I'm can't say whether this will promote all warnings to errors so apologies if you're already aware of this, but there are several MySQL server modes that might work for you:

TRADITIONAL

Make MySQL behave like a “traditional” SQL database system. A simple description of this mode is “give an error instead of a warning” when inserting an incorrect value into a column.

STRICT_ALL_TABLES is part of TRADITIONAL:

Strict mode controls how MySQL handles input values that are invalid or missing. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range



来源:https://stackoverflow.com/questions/4289205/how-can-i-make-fatal-errors-of-all-mysql-warnings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!