linux os errorNo 的解释
我使用过的Linux命令之perror-解释错误代码
博客分类:
Linux命令
LinuxMySQLCentOSerrnoperror
我使用过的Linux命令之perror-解释错误代码
用途说明
perror命令是MySQL数据库系统中的一个工具程序,它用于打印C语言中errno错误代码的含义、也可以打印MySQL中存储引擎错误代码的含义。(perrorprintsadescriptionforasystemerrorcodeorforastorageengine(tablehandler)errorcode.)
由于perror是MySQL中的一个工具程序,在没有安装MySQL的机器上就无法执行,本文的示例四将给出大致的源代码供大家参考。
常用参数
格式:perror<errno>
打印系统错误代码errno值的含义。
格式:perror<Errcode>
打印MySQL数据库系统中定义的错误代码的含义。
格式:perror<err1><err2>...
打印多个错误代码的含义。
manperror写道
Formostsystemerrors,MySQLdisplays,inadditiontoaninternaltextmessage,thesystemerrorcodeinone
ofthefollowingstyles:
message...(errno:#)
message...(Errcode:#)
Linux操作系统中定义的errno值如下所示。
errno.h写道
#defineEPERM1/*Operationnotpermitted*/
#defineENOENT2/*Nosuchfileordirectory*/
#defineESRCH3/*Nosuchprocess*/
#defineEINTR4/*Interruptedsystemcall*/
#defineEIO5/*I/Oerror*/
#defineENXIO6/*Nosuchdeviceoraddress*/
#defineE2BIG7/*Arglisttoolong*/
#defineENOEXEC8/*Execformaterror*/
#defineEBADF9/*Badfilenumber*/
#defineECHILD10/*Nochildprocesses*/
#defineEAGAIN11/*Tryagain*/
#defineENOMEM12/*Outofmemory*/
#defineEACCES13/*Permissiondenied*/
#defineEFAULT14/*Badaddress*/
#defineENOTBLK15/*Blockdevicerequired*/
#defineEBUSY16/*Deviceorresourcebusy*/
#defineEEXIST17/*Fileexists*/
#defineEXDEV18/*Cross-devicelink*/
#defineENODEV19/*Nosuchdevice*/
#defineENOTDIR20/*Notadirectory*/
#defineEISDIR21/*Isadirectory*/
#defineEINVAL22/*Invalidargument*/
#defineENFILE23/*Filetableoverflow*/
#defineEMFILE24/*Toomanyopenfiles*/
#defineENOTTY25/*Notatypewriter*/
#defineETXTBSY26/*Textfilebusy*/
#defineEFBIG27/*Filetoolarge*/
#defineENOSPC28/*Nospaceleftondevice*/
#defineESPIPE29/*Illegalseek*/
#defineEROFS30/*Read-onlyfilesystem*/
#defineEMLINK31/*Toomanylinks*/
#defineEPIPE32/*Brokenpipe*/
#defineEDOM33/*Mathargumentoutofdomainoffunc*/
#defineERANGE34/*Mathresultnotrepresentable*/
#defineEDEADLK35/*Resourcedeadlockwouldoccur*/
#defineENAMETOOLONG36/*Filenametoolong*/
#defineENOLCK37/*Norecordlocksavailable*/
#defineENOSYS38/*Functionnotimplemented*/
#defineENOTEMPTY39/*Directorynotempty*/
#defineELOOP40/*Toomanysymboliclinksencountered*/
#defineEWOULDBLOCKEAGAIN/*Operationwouldblock*/
#defineENOMSG42/*Nomessageofdesiredtype*/
#defineEIDRM43/*Identifierremoved*/
#defineECHRNG44/*Channelnumberoutofrange*/
#defineEL2NSYNC45/*Level2notsynchronized*/
#defineEL3HLT46/*Level3halted*/
#defineEL3RST47/*Level3reset*/
#defineELNRNG48/*Linknumberoutofrange*/
#defineEUNATCH49/*Protocoldrivernotattached*/
#defineENOCSI50/*NoCSIstructureavailable*/
#defineEL2HLT51/*Level2halted*/
#defineEBADE52/*Invalidexchange*/
#defineEBADR53/*Invalidrequestdescriptor*/
#defineEXFULL54/*Exchangefull*/
#defineENOANO55/*Noanode*/
#defineEBADRQC56/*Invalidrequestcode*/
#defineEBADSLT57/*Invalidslot*/
#defineEDEADLOCKEDEADLK
#defineEBFONT59/*Badfontfileformat*/
#defineENOSTR60/*Devicenotastream*/
#defineENODATA61/*Nodataavailable*/
#defineETIME62/*Timerexpired*/
#defineENOSR63/*Outofstreamsresources*/
#defineENONET64/*Machineisnotonthenetwork*/
#defineENOPKG65/*Packagenotinstalled*/
#defineEREMOTE66/*Objectisremote*/
#defineENOLINK67/*Linkhasbeensevered*/
#defineEADV68/*Advertiseerror*/
#defineESRMNT69/*Srmounterror*/
#defineECOMM70/*Communicationerroronsend*/
#defineEPROTO71/*Protocolerror*/
#defineEMULTIHOP72/*Multihopattempted*/
#defineEDOTDOT73/*RFSspecificerror*/
#defineEBADMSG74/*Notadatamessage*/
#defineEOVERFLOW75/*Valuetoolargefordefineddatatype*/
#defineENOTUNIQ76/*Namenotuniqueonnetwork*/
#defineEBADFD77/*Filedescriptorinbadstate*/
#defineEREMCHG78/*Remoteaddresschanged*/
#defineELIBACC79/*Cannotaccessaneededsharedlibrary*/
#defineELIBBAD80/*Accessingacorruptedsharedlibrary*/
#defineELIBSCN81/*.libsectionina.outcorrupted*/
#defineELIBMAX82/*Attemptingtolinkintoomanysharedlibraries*/
#defineELIBEXEC83/*Cannotexecasharedlibrarydirectly*/
#defineEILSEQ84/*Illegalbytesequence*/
#defineERESTART85/*Interruptedsystemcallshouldberestarted*/
#defineESTRPIPE86/*Streamspipeerror*/
#defineEUSERS87/*Toomanyusers*/
#defineENOTSOCK88/*Socketoperationonnon-socket*/
#defineEDESTADDRREQ89/*Destinationaddressrequired*/
#defineEMSGSIZE90/*Messagetoolong*/
#defineEPROTOTYPE91/*Protocolwrongtypeforsocket*/
#defineENOPROTOOPT92/*Protocolnotavailable*/
#defineEPROTONOSUPPORT93/*Protocolnotsupported*/
#defineESOCKTNOSUPPORT94/*Sockettypenotsupported*/
#defineEOPNOTSUPP95/*Operationnotsupportedontransportendpoint*/
#defineEPFNOSUPPORT96/*Protocolfamilynotsupported*/
#defineEAFNOSUPPORT97/*Addressfamilynotsupportedbyprotocol*/
#defineEADDRINUSE98/*Addressalreadyinuse*/
#defineEADDRNOTAVAIL99/*Cannotassignrequestedaddress*/
#defineENETDOWN100/*Networkisdown*/
#defineENETUNREACH101/*Networkisunreachable*/
#defineENETRESET102/*Networkdroppedconnectionbecauseofreset*/
#defineECONNABORTED103/*Softwarecausedconnectionabort*/
#defineECONNRESET104/*Connectionresetbypeer*/
#defineENOBUFS105/*Nobufferspaceavailable*/
#defineEISCONN106/*Transportendpointisalreadyconnected*/
#defineENOTCONN107/*Transportendpointisnotconnected*/
#defineESHUTDOWN108/*Cannotsendaftertransportendpointshutdown*/
#defineETOOMANYREFS109/*Toomanyreferences:cannotsplice*/
#defineETIMEDOUT110/*Connectiontimedout*/
#defineECONNREFUSED111/*Connectionrefused*/
#defineEHOSTDOWN112/*Hostisdown*/
#defineEHOSTUNREACH113/*Noroutetohost*/
#defineEALREADY114/*Operationalreadyinprogress*/
#defineEINPROGRESS115/*Operationnowinprogress*/
#defineESTALE116/*StaleNFSfilehandle*/
#defineEUCLEAN117/*Structureneedscleaning*/
#defineENOTNAM118/*NotaXENIXnamedtypefile*/
#defineENAVAIL119/*NoXENIXsemaphoresavailable*/
#defineEISNAM120/*Isanamedtypefile*/
#defineEREMOTEIO121/*RemoteI/Oerror*/
#defineEDQUOT122/*Quotaexceeded*/
#defineENOMEDIUM123/*Nomediumfound*/
#defineEMEDIUMTYPE124/*Wrongmediumtype*/
使用示例
示例一打印错误代码的含义
[root@jfht~]#perror1
OSerrorcode1:Operationnotpermitted
#defineEPERM1/*Operationnotpermitted*/
[root@jfht~]#perror1364
OSerrorcode13:Permissiondenied
OSerrorcode64:Machineisnotonthenetwork
#defineEACCES13/*Permissiondenied*/
#defineENONET64/*Machineisnotonthenetwork*/
[root@jfht~]#
补充一个:既是操作系统errno,也是MySQL错误代码的。
[root@jfht~]#perror121
OSerrorcode121:RemoteI/Oerror
MySQLerrorcode121:Duplicatekeyonwriteorupdate
示例二打印不存在的错误代码的含义
要注意的是,perror似乎并不能打印SQL执行时所报的错误代码的含义。
mysql>select;
ERROR1064(42000):YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversion
fortherightsyntaxtousenear''atline1、
[root@jfht~]#perror42000
Illegalerrorcode:42000
[root@jfht~]#perror1064
Illegalerrorcode:1064
[root@jfht~]#
示例三枚举所有错误代码
[root@jfht~]#foriin$(seq110000);doperror$i;done>10000.txt2>/dev/null
[root@jfht~]#cat10000.txt
OSerrorcode1:Operationnotpermitted
OSerrorcode2:Nosuchfileordirectory
OSerrorcode3:Nosuchprocess
OSerrorcode4:Interruptedsystemcall
OSerrorcode5:Input/outputerror
OSerrorcode6:Nosuchdeviceoraddress
OSerrorcode7:Argumentlisttoolong
OSerrorcode8:Execformaterror
OSerrorcode9:Badfiledescriptor
OSerrorcode10:Nochildprocesses
OSerrorcode11:Resourcetemporarilyunavailable
OSerrorcode12:Cannotallocatememory
OSerrorcode13:Permissiondenied
OSerrorcode14:Badaddress
OSerrorcode15:Blockdevicerequired
OSerrorcode16:Deviceorresourcebusy
OSerrorcode17:Fileexists
OSerrorcode18:Invalidcross-devicelink
OSerrorcode19:Nosuchdevice
OSerrorcode20:Notadirectory
OSerrorcode21:Isadirectory
OSerrorcode22:Invalidargument
OSerrorcode23:Toomanyopenfilesinsystem
OSerrorcode24:Toomanyopenfiles
OSerrorcode25:Inappropriateioctlfordevice
OSerrorcode26:Textfilebusy
OSerrorcode27:Filetoolarge
OSerrorcode28:Nospaceleftondevice
OSerrorcode29:Illegalseek
OSerrorcode30:Read-onlyfilesystem
OSerrorcode31:Toomanylinks
OSerrorcode32:Brokenpipe
OSerrorcode33:Numericalargumentoutofdomain
OSerrorcode34:Numericalresultoutofrange
OSerrorcode35:Resourcedeadlockavoided
OSerrorcode36:Filenametoolong
OSerrorcode37:Nolocksavailable
OSerrorcode38:Functionnotimplemented
OSerrorcode39:Directorynotempty
OSerrorcode40:Toomanylevelsofsymboliclinks
OSerrorcode42:Nomessageofdesiredtype
OSerrorcode43:Identifierremoved
OSerrorcode44:Channelnumberoutofrange
OSerrorcode45:Level2notsynchronized
OSerrorcode46:Level3halted
OSerrorcode47:Level3reset
OSerrorcode48:Linknumberoutofrange
OSerrorcode49:Protocoldrivernotattached
OSerrorcode50:NoCSIstructureavailable
OSerrorcode51:Level2halted
OSerrorcode52:Invalidexchange
OSerrorcode53:Invalidrequestdescriptor
OSerrorcode54:Exchangefull
OSerrorcode55:Noanode
OSerrorcode56:Invalidrequestcode
OSerrorcode57:Invalidslot
OSerrorcode59:Badfontfileformat
OSerrorcode60:Devicenotastream
OSerrorcode61:Nodataavailable
OSerrorcode62:Timerexpired
OSerrorcode63:Outofstreamsresources
OSerrorcode64:Machineisnotonthenetwork
OSerrorcode65:Packagenotinstalled
OSerrorcode66:Objectisremote
OSerrorcode67:Linkhasbeensevered
OSerrorcode68:Advertiseerror
OSerrorcode69:Srmounterror
OSerrorcode70:Communicationerroronsend
OSerrorcode71:Protocolerror
OSerrorcode72:Multihopattempted
OSerrorcode73:RFSspecificerror
OSerrorcode74:Badmessage
OSerrorcode75:Valuetoolargefordefineddatatype
OSerrorcode76:Namenotuniqueonnetwork
OSerrorcode77:Filedescriptorinbadstate
OSerrorcode78:Remoteaddresschanged
OSerrorcode79:Cannotaccessaneededsharedlibrary
OSerrorcode80:Accessingacorruptedsharedlibrary
OSerrorcode81:.libsectionina.outcorrupted
OSerrorcode82:Attemptingtolinkintoomanysharedlibraries
OSerrorcode83:Cannotexecasharedlibrarydirectly
OSerrorcode84:Invalidorincompletemultibyteorwidecharacter
OSerrorcode85:Interruptedsystemcallshouldberestarted
OSerrorcode86:Streamspipeerror
OSerrorcode87:Toomanyusers
OSerrorcode88:Socketoperationonnon-socket
OSerrorcode89:Destinationaddressrequired
OSerrorcode90:Messagetoolong
OSerrorcode91:Protocolwrongtypeforsocket
OSerrorcode92:Protocolnotavailable
OSerrorcode93:Protocolnotsupported
OSerrorcode94:Sockettypenotsupported
OSerrorcode95:Operationnotsupported
OSerrorcode96:Protocolfamilynotsupported
OSerrorcode97:Addressfamilynotsupportedbyprotocol
OSerrorcode98:Addressalreadyinuse
OSerrorcode99:Cannotassignrequestedaddress
OSerrorcode100:Networkisdown
OSerrorcode101:Networkisunreachable
OSerrorcode102:Networkdroppedconnectiononreset
OSerrorcode103:Softwarecausedconnectionabort
OSerrorcode104:Connectionresetbypeer
OSerrorcode105:Nobufferspaceavailable
OSerrorcode106:Transportendpointisalreadyconnected
OSerrorcode107:Transportendpointisnotconnected
OSerrorcode108:Cannotsendaftertransportendpointshutdown
OSerrorcode109:Toomanyreferences:cannotsplice
OSerrorcode110:Connectiontimedout
OSerrorcode111:Connectionrefused
OSerrorcode112:Hostisdown
OSerrorcode113:Noroutetohost
OSerrorcode114:Operationalreadyinprogress
OSerrorcode115:Operationnowinprogress
OSerrorcode116:StaleNFSfilehandle
OSerrorcode117:Structureneedscleaning
OSerrorcode118:NotaXENIXnamedtypefile
OSerrorcode119:NoXENIXsemaphoresavailable
OSerrorcode120:Isanamedtypefile
MySQLerrorcode120:Didn'tfindkeyonreadorupdate
OSerrorcode121:RemoteI/Oerror
MySQLerrorcode121:Duplicatekeyonwriteorupdate
OSerrorcode122:Diskquotaexceeded
MySQLerrorcode122:Internal(unspecified)errorinhandler
OSerrorcode123:Nomediumfound
MySQLerrorcode123:Someonehaschangedtherowsinceitwasread(whilethetablewaslockedtopreventit)
OSerrorcode124:Wrongmediumtype
MySQLerrorcode124:Wrongindexgiventofunction
OSerrorcode125:Operationcanceled
MySQLerrorcode125:Undefinedhandlererror125
OSerrorcode126:Requiredkeynotavailable
MySQLerrorcode126:Indexfileiscrashed
OSerrorcode127:Keyhasexpired
MySQLerrorcode127:Recordfileiscrashed
OSerrorcode128:Keyhasbeenrevoked
MySQLerrorcode128:Outofmemoryinengine
OSerrorcode129:Keywasrejectedbyservice
MySQLerrorcode129:Undefinedhandlererror129
OSerrorcode130:Ownerdied
MySQLerrorcode130:Incorrectfileformat
OSerrorcode131:Statenotrecoverable
MySQLerrorcode131:Commandnotsupportedbydatabase
MySQLerrorcode132:Olddatabasefile
MySQLerrorcode133:Norecordreadbeforeupdate
MySQLerrorcode134:Recordwasalreadydeleted(orrecordfilecrashed)
MySQLerrorcode135:Nomoreroominrecordfile
MySQLerrorcode136:Nomoreroominindexfile
MySQLerrorcode137:Nomorerecords(readafterendoffile)
MySQLerrorcode138:Unsupportedextensionusedfortable
MySQLerrorcode139:Toobigrow
MySQLerrorcode140:Wrongcreateoptions
MySQLerrorcode141:Duplicateuniquekeyorconstraintonwriteorupdate
MySQLerrorcode142:Unknowncharactersetusedintable
MySQLerrorcode143:Conflictingtabledefinitionsinsub-tablesofMERGEtable
MySQLerrorcode144:Tableiscrashedandlastrepairfailed
MySQLerrorcode145:Tablewasmarkedascrashedandshouldberepaired
MySQLerrorcode146:Locktimedout;Retrytransaction
MySQLerrorcode147:Locktableisfull;Restartprogramwithalargerlocktable
MySQLerrorcode148:Updatesarenotallowedunderareadonlytransactions
MySQLerrorcode149:Lockdeadlock;Retrytransaction
MySQLerrorcode150:Foreignkeyconstraintisincorrectlyformed
MySQLerrorcode151:Cannotaddachildrow
MySQLerrorcode152:Cannotdeleteaparentrow
MySQLerrorcode153:Nosavepointwiththatname
MySQLerrorcode154:Nonuniquekeyblocksize
MySQLerrorcode155:Thetabledoesnotexistinengine
MySQLerrorcode156:Thetablealreadyexistedinstorageengine
MySQLerrorcode157:Couldnotconnecttostorageengine
MySQLerrorcode158:Unexpectednullpointerfoundwhenusingspatialindex
MySQLerrorcode159:Thetablechangedinstorageengine
MySQLerrorcode160:There'snopartitionintableforthegivenvalue
MySQLerrorcode161:Row-basedbinloggingofrowfailed
MySQLerrorcode162:Indexneededinforeignkeyconstraint
MySQLerrorcode163:Upholdingforeignkeyconstraintswouldleadtoaduplicatekeyerrorinsomeothertable
MySQLerrorcode164:Tableneedstobeupgradedbeforeitcanbeused
MySQLerrorcode165:Tableisreadonly
MySQLerrorcode166:Failedtogetnextautoincrementvalue
MySQLerrorcode167:Failedtosetrowautoincrementvalue
MySQLerrorcode168:Unknown(generic)errorfromengine
MySQLerrorcode169:Recordisthesame
MySQLerrorcode170:Itisnotpossibletologthisstatement
MySQLerrorcode171:Theeventwascorrupt,leadingtoillegaldatabeingread
MySQLerrorcode172:Thetableisofanewformatnotsupportedbythisversion
MySQLerrorcode173:Theeventcouldnotbeprocessednootherhanldererrorhappened
MySQLerrorcode174:Gotafatalerrorduringinitialzactionofhandler
MySQLerrorcode175:Filetoshort;Expectedmoredatainfile
MySQLerrorcode176:Readpagewithwrongchecksum
MySQLerrorcode177:Toomanyactiveconcurrenttransactions
[root@jfht~]#
示例四perror大体的C语言代码
[root@centos55~]#perror
-bash:perror:commandnotfound
[root@centos55~]#
[root@centos55~]#cat>perror.c
#include<stdio.h>
#include<errno.h>
#include<stdlib.h>
#include<string.h>
intmain(intargc,char*argv[])
{
if(argc==1)
{
fprintf(stderr,"usage:%s<errno>[<errno>...]\n",argv[0]);
exit(1);
}
else
{
inti;
for(i=1;i<argc;++i)
{
intec=strtoul(argv[i],0,0);
fprintf(stdout,"OSerrorcode%d:%s\n",ec,strerror(ec));
}
exit(0);
}
}
[root@centos55~]#gcc-Wall-o/usr/bin/perrorperror.c
[root@centos55~]#perror1
OSerrorcode1:Operationnotpermitted
[root@centos55~]#
注:该源代码无法对非法的错误代码进行判断。perror程序在提供的错误代码非法时会在标准错误设备上输出信息,而不是标准输出设备。
问题思考
相关资料
【1】MySQL中文手册perror—ExplainErrorCodes
http://dev.mysql.com/doc/refman/5.0/en/perror.html
返回我使用过的Linux命令系列总目录