Where I can find a list of “mysqldump” exit codes?

孤者浪人 提交于 2019-11-27 09:15:50

Taken from client/mysqldump.c in MySQL 5.1.59:

#define EX_USAGE 1
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4
#define EX_EOF 5 /* ferror for output file was got */
#define EX_ILLEGAL_TABLE 6

Skimming through the source, EX_MYSQLERR seems to be used mostly for errors from the server, but also in case malloc fails. CONSCHECK seems to stand for consistency checks. EX_EOM is returned for some _alloc calls too - "End Of Memory"?

fbitterlich

Exit code 2 often occurs when the dump could not be completed due to privilege problems; for example, if the user does not have the LOCK TABLES privilege, or the supplied password was wrong.

This is worth noting that if you use mysqldump in php function exec, shell_exec or system as command it will return 02 exit code if you do not have permissions to write file into selected location.

In my case command:

mysqldump '-uUSER' '-pPASS' DATABASE > /home/USER/LOCATION/dump.sql

When called from php did not work. It was solved after adding proper write permissions to LOCATION folder.

I solved it by checking what was sent as output when calling command:

myslqdump

and after it:

mysqldump '-uUSER' '-pPASS' DATABASE

In both cases command gave proper response in 2nd argument of exec function.

Another reason might be a password with too special chars, which was used unescaped on the console (since you use mysqldump). The process returns the error code 2 too. I have this problem from time to time. Wrapping params at least in quotes / double-quotes helps often: Instead -u... -p... and so on, using "-u..." "-p..." eliminates many problems. However it is not a perfect solution (if the same type of quotes are used).

It can also be an OS dependent problem. MS Windows for example uses variables, like %MYVAR% which seems not be able to be escaped at all (at least some sources like the PHP docu mentions this).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!