MySQL利用perror命令查看错误代码信息

文章目录

  • 【MySQL】利用perror命令查看错误代码信息
    • perror帮助信息
    • perror使用例
    • 参考

【声明】文章仅供学习交流,观点代表个人,与任何公司无关。
编辑|SQL和数据库技术(ID:SQLplusDB)

MySQL 8.0 OCP (1Z0-908) 考点概要
MySQL 8.0 OCP (1Z0-908) 考点精析-安装与配置考点1:设置系统变量
【MySQL】控制MySQL优化器行为方法之optimizer_switch系统变量
【MySQL】MySQL系统变量(system variables)列表(mysqld --verbose --help的结果例)
【MySQL】MySQL系统变量(system variables)列表(SHOW VARIABLES 的结果例)
MySQL 8.0 OCP (1Z0-908) 考点精析-备份与恢复考点1:MySQL Enterprise Backup概要
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点1:sys.statement_analysis视图
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点2:系统变量的确认
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点3:EXPLAIN ANALYZE
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点4:慢速查询日志(slow query log)
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点5:表连接算法(join algorithm)
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点6:MySQL Enterprise Monitor之Query Analyzer
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点1:二进制日志文件(Binary log)
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点5:数据字典(Data Dictionary)
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点6:InnoDB Tablespaces之系统表空间(System Tablespace)
MySQL 8.0 InnoDB Tablespaces之File-per-table tablespaces(单独表空间)
MySQL 8.0 InnoDB Tablespaces之General Tablespaces(通用表空间/一般表空间)
【MySQL】在数据目录之外创建InnoDB 表(Creating Tables Externally)
MySQL 8.0 InnoDB Tablespaces之Temporary Tablespaces(临时表空间)
MySQL 8.0 InnoDB 架构之 日志缓冲区(Log Buffer)和重做日志(Redo Log)
MySQL 8.0 架构 之错误日志文件(Error Log)(1)
【MySQL】MySQL 8.0 状态变量(Server Status Variables)以及SHOW STATUS命令
【MySQL】MySQL 8.0 状态变量(Server Status Variables)列表(show status 的结果例)
【MySQL】利用perror命令查看错误代码信息

【MySQL】利用perror命令查看错误代码信息

对于Oracle数据库,通过oerr命令可以查看Oracle数据库错误代码信息以及一般的解决方法信息。

例: Linux

[oracle@ ~]$ oerr ora 60
00060, 00000, "deadlock detected while waiting for resource"
// *Cause :  Transactions deadlocked one another while waiting for resources.
// *Action: Look at the trace file to see the transactions and resources
//          involved. Retry if necessary.

Win:

C:UsersAdministrator>oerr ora 384
00384, 00000, "Insufficient memory to grow cache"
// *Cause:  The system could not allocate sufficient memory to grow the
//          cache to the specified size.
// *Action: Attempt a smaller increase in the value of the parameter.

C:UsersAdministrator>oerr ora 32017
32017, 00000, "failure in updating SPFILE"
// *Cause:  A failure occured while updating the SPFILE.
// *Action: See associated errors.

同样,MySQL服务器,也提供了perror命令用于帮助用户查看MySQL或者操作系统的错误信息。
可以通过如下格式使用perror命令

perror [options] errorcode ...

perror帮助信息

在命令行上直接输入perror(或者perror -?)命令可以获得perror的帮助信息

例:

ubuntu@mysql-vm:~$ which perror
/usr/bin/perror
ubuntu@mysql-vm:~$ perror
perror  Ver 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Print a description for a system error code or a MySQL error code.
If you want to get the error for a negative error code, you should use
-- before the first error code to tell perror that there was no more options.

Usage: perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  -?, --help          Displays this help and exits.
  -I, --info          Synonym for --help.
  -s, --silent        Only print the error message.
  -v, --verbose       Print error code and message (default).
                      (Defaults to on; use --skip-verbose to disable.)
  -V, --version       Displays version information and exits.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
verbose                           TRUE

perror使用例

例如我们要查看MY-000001错误的信息,可以使用如下命令。

ubuntu@mysql-vm:~$ perror 1
OS error code   1:  Operation not permitted
MySQL error code MY-000001: Can't create/write to file '%s' (OS errno %d - %s)
ubuntu@mysql-vm:~$
ubuntu@mysql-vm:~$  perror 5
OS error code   5:  Input/output error
MySQL error code MY-000005: Out of memory (Needed %u bytes)
ubuntu@mysql-vm:~$
ubuntu@mysql-vm:~$  perror 1109
MySQL error code MY-001109 (ER_UNKNOWN_TABLE): Unknown table '%-.192s' in %-.32s
ubuntu@mysql-vm:~$

可以看到perror会同时返回操作系统和MySQL相同错误代码的信息。

参考

4.8.2 perror — Display MySQL Error Message Information
https://dev.mysql.com/doc/refman/8.0/en/perror.html