Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code DEF204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher dans le manuel MySQL

13.7.6.40 SHOW WARNINGS Syntax

SHOW WARNINGS is a diagnostic statement that displays information about the conditions (errors, warnings, and notes) resulting from executing a statement in the current session. Warnings are generated for DML statements such as INSERT, UPDATE, and LOAD DATA as well as DDL statements such as CREATE TABLE and ALTER TABLE.

The LIMIT clause has the same syntax as for the SELECT statement. See Section 13.2.10, “SELECT Syntax”.

SHOW WARNINGS is also used following EXPLAIN, to display the extended information generated by EXPLAIN. See Section 8.8.3, “Extended EXPLAIN Output Format”.

SHOW WARNINGS displays information about the conditions resulting from execution of the most recent nondiagnostic statement in the current session. If the most recent statement resulted in an error during parsing, SHOW WARNINGS shows the resulting conditions, regardless of statement type (diagnostic or nondiagnostic).

The SHOW COUNT(*) WARNINGS diagnostic statement displays the total number of errors, warnings, and notes. You can also retrieve this number from the warning_count system variable:

  1. SELECT @@warning_count;

A difference in these statements is that the first is a diagnostic statement that does not clear the message list. The second, because it is a SELECT statement is considered nondiagnostic and does clear the message list.

A related diagnostic statement, SHOW ERRORS, shows only error conditions (it excludes warnings and notes), and SHOW COUNT(*) ERRORS statement displays the total number of errors. See Section 13.7.6.17, “SHOW ERRORS Syntax”. GET DIAGNOSTICS can be used to examine information for individual conditions. See Section 13.6.7.3, “GET DIAGNOSTICS Syntax”.

Here is a simple example that shows data-conversion warnings for INSERT. The example assumes that strict SQL mode is disabled. With strict mode enabled, the warnings would become errors and terminate the INSERT.

  1. mysql> CREATE TABLE t1 (a TINYINT NOT NULL, b CHAR(4));
  2. Query OK, 0 rows affected (0.05 sec)
  3.  
  4. mysql> INSERT INTO t1 VALUES(10,'mysql'), (NULL,'test'), (300,'xyz');
  5. Query OK, 3 rows affected, 3 warnings (0.00 sec)
  6. Records: 3  Duplicates: 0  Warnings: 3
  7.  
  8. mysql> SHOW WARNINGS\G
  9. *************************** 1. row ***************************
  10.   Level: Warning
  11.    Code: 1265
  12. Message: Data truncated for column 'b' at row 1
  13. *************************** 2. row ***************************
  14.   Level: Warning
  15.    Code: 1048
  16. Message: Column 'a' cannot be null
  17. *************************** 3. row ***************************
  18.   Level: Warning
  19.    Code: 1264
  20. Message: Out of range value for column 'a' at row 3
  21. 3 rows in set (0.00 sec)

The max_error_count system variable controls the maximum number of error, warning, and note messages for which the server stores information, and thus the number of messages that SHOW WARNINGS displays. To change the number of messages the server can store, change the value of max_error_count.

max_error_count controls only how many messages are stored, not how many are counted. The value of warning_count is not limited by max_error_count, even if the number of messages generated exceeds max_error_count. The following example demonstrates this. The ALTER TABLE statement produces three warning messages (strict SQL mode is disabled for the example to prevent an error from occuring after a single conversion issue). Only one message is stored and displayed because max_error_count has been set to 1, but all three are counted (as shown by the value of warning_count):

  1. mysql> SHOW VARIABLES LIKE 'max_error_count';
  2. +-----------------+-------+
  3. | Variable_name   | Value |
  4. +-----------------+-------+
  5. | max_error_count | 1024  |
  6. +-----------------+-------+
  7. 1 row in set (0.00 sec)
  8.  
  9. mysql> SET max_error_count=1, sql_mode = '';
  10. Query OK, 0 rows affected (0.00 sec)
  11.  
  12. mysql> ALTER TABLE t1 MODIFY b CHAR;
  13. Query OK, 3 rows affected, 3 warnings (0.00 sec)
  14. Records: 3  Duplicates: 0  Warnings: 3
  15.  
  16. mysql> SHOW WARNINGS;
  17. +---------+------+----------------------------------------+
  18. | Level   | Code | Message                                |
  19. +---------+------+----------------------------------------+
  20. | Warning | 1263 | Data truncated for column 'b' at row 1 |
  21. +---------+------+----------------------------------------+
  22. 1 row in set (0.00 sec)
  23.  
  24. mysql> SELECT @@warning_count;
  25. +-----------------+
  26. | @@warning_count |
  27. +-----------------+
  28. |               3 |
  29. +-----------------+
  30. 1 row in set (0.01 sec)

To disable message storage, set max_error_count to 0. In this case, warning_count still indicates how many warnings occurred, but messages are not stored and cannot be displayed.

The sql_notes system variable controls whether note messages increment warning_count and whether the server stores them. By default, sql_notes is 1, but if set to 0, notes do not increment warning_count and the server does not store them:

  1. mysql> SET sql_notes = 1;
  2. mysql> DROP TABLE IF EXISTS test.no_such_table;
  3. Query OK, 0 rows affected, 1 warning (0.00 sec)
  4. mysql> SHOW WARNINGS;
  5. +-------+------+------------------------------------+
  6. | Level | Code | Message                            |
  7. +-------+------+------------------------------------+
  8. | Note  | 1051 | Unknown table 'test.no_such_table' |
  9. +-------+------+------------------------------------+
  10. 1 row in set (0.00 sec)
  11.  
  12. mysql> SET sql_notes = 0;
  13. mysql> DROP TABLE IF EXISTS test.no_such_table;
  14. Query OK, 0 rows affected (0.00 sec)
  15. mysql> SHOW WARNINGS;
  16. Empty set (0.00 sec)

The MySQL server sends to each client a count indicating the total number of errors, warnings, and notes resulting from the most recent statement executed by that client. From the C API, this value can be obtained by calling mysql_warning_count(). See Section 28.7.7.82, “mysql_warning_count()”.

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.1.2, “mysql Client Commands”). For example:

  1. mysql> \W
  2. Show warnings enabled.
  3. mysql> SELECT 1/0;
  4. +------+
  5. | 1/0  |
  6. +------+
  7. | NULL |
  8. +------+
  9. 1 row in set, 1 warning (0.03 sec)
  10.  
  11. Warning (Code 1365): Division by 0
  12. mysql> \w
  13. Show warnings disabled.

Suchen Sie im MySQL-Handbuch

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-show-warnings.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:en Manuel MySQL : https://dev.mysql.com/

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut