I have an extremely simple script with PHP exec, calling mysql command:
$dbhost = \'localhost\';
$dbuser = \'root\';
$dbpass
This was happening to me too even on Ubuntu. The problem was that i was doing the following code:
$mysql = shell_exec("sudo which mysql");
$cmd = "$mysql --host=$host --user=$user --password=$pass -D $dbname -e 'source $base_sql_file'";
exec($cmd, $output, $retvar);
Only a slight detail was missing... the shell_exec returns the output with trailling characters. When executing the command i was getting a MySQL error 127 (Record is crashed).
The solution was simple: add a trim function to shell_exec :)
$mysql = trim(shell_exec("sudo which mysql"));
$cmd = "$mysql --host=$host --user=$user --password=$pass -D $dbname -e 'source $base_sql_file'";
exec($cmd, $output, $retvar);