MySQL increase in reading abnormal and Error Buffer (MySQL 5.6)

Source: Internet
Author: User


MySQL's increase in reading the exceptional Error Buffer (MySQL 5.6) first explains what is an error buffer? In MySQL, the Error Buffer only records the last error. If a new error is generated, the old one will be overwritten. To know what error occurs, www.2cto.com must follow "show warnings" or "show errors" after each statement that may have an error ". The simplest way is to redirect the output result to the custom log file, so that it can be conveniently viewed later. If you want to view these errors at any time, you must use the APIS provided by MySQL. Since the emergence of the revolutionary MySQL 5.6 version, the problem has been preliminarily solved. Although it is far from what we think. MySQL 5.6 provides the get diagnostic statement to get the content of the Error Buffer, and then output the content to variables in different range fields, so that we can flexibly perform subsequent operations. Next, let's look at an example. The TABLE structure for www.2cto.com is: [SQL] CREATE TABLE 't_ datetime' ('id' int (11) NOT NULL, 'Log _ time' timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, 'end _ time' datetime not null, primary key ('id ')) ENGINE = InnoDB default charset = utf8 Stored Procedure Code: [SQL] DELIMITER $ www.2cto.com USE 'new _ t' $ DROP PROCEDURE IF EXISTS 'SP _ do_update '$ CREATE DEFINER = 'root' @ 'localhost' PROCEDURE 'SP _ do_upd Ate '(IN f_id INT, IN f_log_time VARCHAR (255), IN f_end_time VARCHAR (255) begin declare I _con1 tinyint default 0; DECLARE I _code CHAR (5) DEFAULT '100 '; DECLARE I _msg TEXT; DECLARE I _rows INT; DECLARE I _con1 CONDITION FOR 1048; -- this error code indicates that the field cannot be NULL. Declare continue handler for I _con1 begin set I _con1 = 1; get diagnostics CONDITION 1 I _code = CONDITION, I _msg = message_text; END; BEGIN UPDATE t_datetime SET log_time = IFNULL (f_log_time, NULL ), end_time = IFNULL (f_end_time, NULL) WHERE id = f_id; IF I _con1 = 0 THEN get diagnostics I _rows = ROW_COUNT; SET @ I _result = CONCAT ("Update succeeded, affected", I _rows, '. '); else set @ I _re Sult = CONCAT ('Update failed, error code is 1042, related message is ', I _msg ,'. '); end if; SELECT @ I _result; END $ DELIMITER; let's execute the above stored procedure. After the execution, we can save the error information to the SESSION variable @ I _result. This facilitates the subsequent output. Www.2cto.com [SQL] CALL sp_do_update (1, NOW (), DATE_ADD (NOW (), INTERVAL 1 DAY); Result. update succeeded, affected 1. CALL sp_do_update (1, NULL, NULL); Result. update failed, error code is 1042, related message is Column 'Log _ time' cannot be null. author siye

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.