简体   繁体   中英

Why do I get this error when trying to use mysqldump command?

I want to back up and roll back the back up on a database, and I'm trying to see what's wrong:

'mysqldump' is not recognized as an internal or external command, operable program or batch file.

The above is what I get in the file that is exported. And this is what I run:

$database = 'logindb';

$backup = $location.'/'.$database.'_backup_'.date('Y').'_'.date('m').'_'.date('d').'.sql';

exec("mysqldump --opt -h localhost -u root logindb > $backup 2>&1", $output);
print_r($output);

As $location being my backup folder. So why do I get that error ?

And as additional info, I'm testing on localhost with XAAMP, the Apache server is running and MySQL is running as wel.

Because mysqldump is not in httpd user path.

I asume you work in Linux (or UNIX).

To know witch directory contains mysqldump you can execute whereis mysqldump .

Then you have two options:

  • Check for mysqldump directory is in PATH environment variable of httpd user (usualy www-data user for apache server). And include it in PATH is it not present.

  • Also you can execute mysqldump with full path:

Like this:

exec("/path_to_mysql_bins/mysqldump ...

The error is not a mysqldump error, it's a Windows error that says that it does not understand what mysqldump relates to. To fix that you can either include the path to mysqldump executable to the environment variables or run the exec command with a full path to the mysqldump executable (which you can find within XAMPP mysql folder).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM