MySQL DBA Session 4 interpreting error messages

14
Session 4. Interpreting Error and Diagnostic Information RAM N SANGWAN WWW.HOMETUTOR.NET.IN HTTP://YOUTUBE.COM/USER/THESKILLPEDIA

Transcript of MySQL DBA Session 4 interpreting error messages

Page 1: MySQL DBA Session 4 interpreting error messages

Session 4. Interpreting Error and Diagnostic InformationRAM N SANGWAN

WWW.HOMETUTOR.NET. IN

HT TP://YOUTUBE.COM/USER/THESKILLPEDIA

Page 2: MySQL DBA Session 4 interpreting error messages

Error Messages

• If problems occur when you attempt to connect to MySQL Server with a clientprogram or while the server attempts to execute the SQL statements thatyou send to it, MySQL produces diagnostic messages.

• Clients can display this information to assist you in troubleshooting andresolving problems.

• Diagnostics might be error messages or warning messages.

R.N. SANGWAN (WWW.RNSANGWAN.COM) 2

Page 3: MySQL DBA Session 4 interpreting error messages

Error Messages – Contd..

MySQL provides diagnostic information in the following way:

• An error message is returned for statements that fail:mysql> SELECT * FROM no_such_table;

ERROR 1146 (42S02): Table'test.no_such_table' doesn't exist

• These messages typically have three components :◦ A MySQL-specific error code.

◦ An SQLSTATE error code defined by standard SQL and ODBC.

◦ A text message that describes the problem.

R.N. SANGWAN (WWW.RNSANGWAN.COM) 3

Page 4: MySQL DBA Session 4 interpreting error messages

Error Messages Contd…

An information string is returned by statements that affect multiple rows.

This string provides a summary of the statement outcome:mysql> CREATE TABLE integers (i INT UNSIGNED NOT NULL);

mysql> INSERT INTO integers VALUES ('abc'), (-5), (NULL);

Query OK, 3 rows affected, 3 warnings (0.00 sec)

Records: 3 Duplicates: 0 Warnings: 3

R.N. SANGWAN (WWW.RNSANGWAN.COM) 4

Page 5: MySQL DBA Session 4 interpreting error messages

Error Messages Contd..

• An operating system-level error might occur:mysql> CREATE TABLE CountryCopy SELECT * FROM Country;

ERROR 1 (HY000): Can't create/write to file './world/CountryCopy.frm'

(Errcode: 13)

• The information string for multiple-row statements is a summary.

• An operating system error includes an Errcode number that might have asystem-specific meaning. For ExampleError Code 13 : Permission Denied

Error Code 28 : No Space Left on Device

Error Code 64 : Machine not on Network

Error Code 2 : No such File or Directory

R.N. SANGWAN (WWW.RNSANGWAN.COM) 5

Page 6: MySQL DBA Session 4 interpreting error messages

Show Warnings

You can use the following means to obtain assistance in interpreting diagnosticinformation:

• The SHOW WARNINGS and SHOW ERRORS statements display warning and errorinformation for statements that produce diagnostic information.

• The perror command-line utility displays the meaning of operating system-related error codes.

R.N. SANGWAN (WWW.RNSANGWAN.COM) 6

Page 7: MySQL DBA Session 4 interpreting error messages

The SHOW WARNINGS Statement

• MySQL Server generates warnings when it is not able to fully comply with arequest. These warnings can be displayed with the SHOW WARNINGSstatement.

• For Example, warnings are generated for attempts to insert a character string, anegative integer, and NULL into a column that is defined as INT UNSIGNED NOTNULL :mysql> CREATE TABLE integers (i INT UNSIGNED NOT NULL);

Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO integers VALUES ('abc'), (-5), (NULL);

Query OK, 3 rows affected, 3 warnings (0.00 sec)

Records: 3 Duplicates: 0 Warnings: 3

R.N. SANGWAN (WWW.RNSANGWAN.COM) 7

Page 8: MySQL DBA Session 4 interpreting error messages

Show Warning …

• When a statement cannot be executed without some sort of problem occurring,the SHOW WARNINGS statement provides information to help you understandwhat went wrong:mysql> SHOW WARNINGS\G

• You can combine SHOW WARNINGS with LIMIT, just as you're used to doingwith SELECT statements, to "scroll" through the warnings a section at a time:mysql> SHOW WARNINGS LIMIT 1,2\G

• If you want to know only how many warnings there were, use SHOW COUNT(*)WARNINGS.mysql> SHOW COUNT(*) WARNINGS;

R.N. SANGWAN (WWW.RNSANGWAN.COM) 8

Page 9: MySQL DBA Session 4 interpreting error messages

Show Warnings Contd..

• Warnings generated by one statement are available from the server until youissue another statement that can generate warnings.

• "Warnings" actually can occur at several levels of severity:o Error messages indicate serious problems that prevent the server from

completing a request.

o Warning messages indicate problems for which the server can continueprocessing the request.

o Note messages are informational only.

R.N. SANGWAN (WWW.RNSANGWAN.COM) 9

Page 10: MySQL DBA Session 4 interpreting error messages

Show Warnings.. Contd..

An error occurs for the SELECT statement. For the DELETE statement, the messageis only a note. That is certainly true when the statement finishes, even though thestatement did nothing.

mysql> SELECT * FROM no_such_table;

mysql> SHOW WARNINGS;

mysql> DROP TABLE IF EXISTS no_such_table;

mysql> SHOW WARNINGS;

• To suppress generation of Note warnings, you can set the sql_notes systemvariable to zero:mysql> SET sql_notes = 0;

R.N. SANGWAN (WWW.RNSANGWAN.COM) 10

Page 11: MySQL DBA Session 4 interpreting error messages

The SHOW ERRORS Statement

• The SHOW ERRORS statement is similar to SHOW WARNINGS, but displays onlymessages for error conditions.

• SHOW ERRORS, like SHOW WARNINGS, supports a LIMIT clause to restrict thenumber of rows to return.

• It also can be used as SHOW COUNT(*) ERRORS to obtain a count of the errormessages.

R.N. SANGWAN (WWW.RNSANGWAN.COM) 11

Page 12: MySQL DBA Session 4 interpreting error messages

The perror Utility

• The purpose of the perror program is to show you information about the errorcodes used by MySQL when operating system-level errors occur.mysql> CREATE TABLE CountryCopy SELECT * FROM Country;

ERROR 1 (HY000): Can't create/write to file'./world/CountryCopy.frm'

(Errcode: 13)

R.N. SANGWAN (WWW.RNSANGWAN.COM) 12

Page 13: MySQL DBA Session 4 interpreting error messages

Perror … Contd..

• Above error message indicates that MySQL cannot write to thefile CountryCopy.frm, but does not report the reason.

• To find out, run the perror program with an argument of the number givenfollowing Errcode in the preceding error message.shell> perror 13

Error code 13: Permission denied

R.N. SANGWAN (WWW.RNSANGWAN.COM) 13

Page 14: MySQL DBA Session 4 interpreting error messages

Thank You