简体   繁体   中英

mysql dump using php script

I tried the below code to backup my database "db_school".

<?php
    shell_exec('mysqldump -u root -h localhost db_school > backup-file.sql');
?>

The new file named "backup-file.sql" is created but, the problem is that it is totally empty. Following is my database table:

-------------------------------------
id  |  school_name   |  city
-------------------------------------
1   |  cp school     |  New York
2   |  public school |  San Fracisco
-------------------------------------

Note: my 'root' user has no password I know there are many posts on this topic but each suggests the code similar to above

Make sure folder having full permission (777 read/write).

because this code create new file name "backup-file.sql" , so folder having permission to create new file.

please give the permission to that folder where this php file executes.

try this dear

a set of one or more complete databases

<?php
    shell_exec('mysqldump -u root -h localhost --database db_school > backup-file.sql');
?>

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