I know that exit code = 0
means No error
.
I got exit code = 2
. What does it means ?
Where I can see the complete list of mysqldump
exit codes ?
I know that exit code = 0
means No error
.
I got exit code = 2
. What does it means ?
Where I can see the complete list of mysqldump
exit codes ?
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"?
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).