Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make fatal errors of ALL mysql warnings?

Tags:

mysql

warnings

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

like image 335
Eugene Yarmash Avatar asked Nov 26 '10 23:11

Eugene Yarmash


People also ask

How do I get an error message in mysql?

We can display error message in case of an error generated by MySQL query. This meaning full error message gives idea one the problem or bugs in the script. We can print the error message by using mysql function mysql_error(). This function returns the error message associated with most recently executed query.

How do I enable warnings in mysql?

In the mysql client, you can enable and disable automatic warnings display using the warnings and nowarning commands, respectively, or their shortcuts, \W and \w (see Section 4.5.

What is the command to see warning messages?

Correct Option: B The SHOW WARNINGS command is used after executing one of those statements to see the warning messages.


2 Answers

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

like image 157
Pekka Avatar answered Sep 23 '22 05:09

Pekka


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.

like image 23
fredt Avatar answered Sep 24 '22 05:09

fredt