【MySQL】SHOW WARNINGS和SHOW ERRORS的做用是什麼?

【MySQL】SHOW WARNINGS和SHOW ERRORS的做用是什麼?



真題一、SHOW WARNINGSSHOW ERRORS的做用是什麼? html

答案:SHOW WARNINGS能夠顯示上一個命令的警告信息,SHOW ERRORS能夠顯示上一個命令的錯誤信息。其它用法見下表: mysql

 

命令 面試

解釋 sql

語法命令 數據庫

SHOW WARNINGS [LIMIT [offset,] row_count] 微信

查看警告信息的語法。 網絡

SHOW ERRORS [LIMIT [offset,] row_count] session

查看錯誤信息的語法。 app

查看信息 less

SHOW WARNINGS

查看上一個命令的警告信息。

SHOW ERRORS

查看上一個命令的錯誤信息。

查看行數

SHOW COUNT(*) WARNINGS

SELECT @@warning_count;

查看上一個命令的警告數。

SHOW COUNT(*) ERRORS

SELECT @@error_count;

查看上一個命令的錯誤數。

參數

max_error_count

默認爲64,控制能夠記錄的最大信息數,包括ERRORSWARINGSSHOW ERRORSSHOW WARNINGS的顯示結果不會超過該值,可是「SELECT @@error_count;」「SELECT @@warning_count;」能夠超過該值。能夠設置該值爲0來禁用信息存儲,此時SHOW ERRORSSHOW WARNINGS沒有結果,可是「SELECT @@error_count;」「SELECT @@warning_count;」依然有值。

sql_notes

控制是否記錄錯誤和警告信息,默認爲1,表示啓用,0表示禁用。

是否自動顯示警告信息的內容

\Wwarnings

在每一個SQL執行完後自動顯示告警信息的內容。

\wnowarning

默認值,在每一個SQL執行完後不自動顯示告警信息的內容,只顯示數量。

 




   
官網:  
   https://dev.mysql.com/doc/refman/5.6/en/show-warnings.html  
https://dev.mysql.com/doc/refman/5.7/en/show-errors.html  




 mysql> ? SHOW WARNINGS;  
Name: 'SHOW WARNINGS'  
Description:  
Syntax:  
SHOW WARNINGS [LIMIT [offset,] row_count]  
SHOW COUNT(*) WARNINGS  


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 INFILE 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  
http://dev.mysql.com/doc/refman/5.7/en/select.html.  


SHOW WARNINGS is also used following EXPLAIN, to display the extended  
information generated by EXPLAIN. See  
http://dev.mysql.com/doc/refman/5.7/en/explain-extended.html.  


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:  


SHOW COUNT(*) WARNINGS;  
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 [HELP SHOW ERRORS].  
GET DIAGNOSTICS can be used to examine information for individual  
conditions. See [HELP GET DIAGNOSTICS].  

 
URL: http://dev.mysql.com/doc/refman/5.7/en/show-warnings.html  

 



 
 mysql> ? show errors;  
Name: 'SHOW ERRORS'  
Description:  
Syntax:  
SHOW ERRORS [LIMIT [offset,] row_count]  
SHOW COUNT(*) ERRORS  


SHOW ERRORS is a diagnostic statement that is similar to SHOW WARNINGS,  
except that it displays information only for errors, rather than for  
errors, warnings, and notes.  


The LIMIT clause has the same syntax as for the SELECT statement. See  
http://dev.mysql.com/doc/refman/5.7/en/select.html.  


The SHOW COUNT(*) ERRORS statement displays the number of errors. You  
can also retrieve this number from the error_count variable:  


SHOW COUNT(*) ERRORS;  
SELECT @@error_count;  


SHOW ERRORS and error_count apply only to errors, not warnings or  
notes. In other respects, they are similar to SHOW WARNINGS and  
warning_count. In particular, SHOW ERRORS cannot display information  
for more than max_error_count messages, and error_count can exceed the  
value of max_error_count if the number of errors exceeds  
max_error_count.  


URL: http://dev.mysql.com/doc/refman/5.7/en/show-errors.html  


 
 





一、SHOW ERRORS 語句只是顯示上一個語句的錯誤,不一樣時顯示警告以及注意事項。  
舉個例子:  

mysql> show dfdafsadf  
    -> ;  
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that  
corresponds to your MySQL server version for the right syntax to use near 'dfdaf  
sadf' at line 1  

這裏就有個錯誤。關於如何顯示她,已經很明顯了。  

mysql> show errors  
    -> \G  
*************************** 1. row ***************************  
  Level: Error  
   Code: 1064  
Message: You have an error in your SQL syntax; check the manual that corresponds  
 to your MySQL server version for the right syntax to use near 'dfdafsadf' at li  
ne 1  
1 row in set (0.00 sec)  

若是一會兒有好多錯誤,而你又想只顯示第二條的話:  
show errorw limit 1,1;  
若是你想看到有錯誤的數目,前面的 1 rows in set 已經很明顯了。  
不過還有辦法:  
mysql> show count(*) errors;  
+-----------------------+  
| @@session.error_count |  
+-----------------------+  
|                     1 |  
+-----------------------+  
1 row in set (0.00 sec)  
注意:這裏的count(*)不能寫成count(1).  
你還能夠這樣:  
mysql> select @@error_count;  
+---------------+  
| @@error_count |  
+---------------+  
|             1 |  
+---------------+  
1 row in set (0.00 sec)  

二、SHOW WARNINGS 顯示上一個語句的錯誤、警告以及注意。  
基本語法和SHOW ERRORS大同小異。  
不過要注意的是在MYSQL5後的大部分之前的WARNINGS直接被顯示爲ERRORS。  











About Me

.............................................................................................................................................

● 本文做者:小麥苗,部份內容整理自網絡,如有侵權請聯繫小麥苗刪除

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客園(http://www.cnblogs.com/lhrbest)和我的微信公衆號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、我的簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 數據庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ羣號:230161599(滿)、618766405

● 微信羣:可加我微信,我拉你們進羣,非誠勿擾

● 聯繫我請加QQ好友646634621,註明添加原因

● 於 2017-12-01 09:00 ~ 2017-12-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網絡,如有侵權或不當之處還請諒解

● 版權全部,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麥苗出版的數據庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公衆號(xiaomaimiaolhr)及QQ羣(DBA寶典),學習最實用的數據庫技術。

   小麥苗的微信公衆號      小麥苗的DBA寶典QQ羣2     《DBA筆試面寶典》讀者羣       小麥苗的微店

.............................................................................................................................................

ico_mailme_02.png
DBA筆試面試講解羣
《DBA寶典》讀者羣 歡迎與我聯繫




來自 「 ITPUB博客 」 ,連接:http://blog.itpub.net/26736162/viewspace-2149036/,如需轉載,請註明出處,不然將追究法律責任。

相關文章
相關標籤/搜索