Amit Dhamu

Writes Code

Backup & Restore MySQL Tables & Databases

In order for this to work, you will need to copy mysqldump.exe and mysql.exe from the MySQL bin Program Files folder into the same directory as your executing PHP script. If you know the direct path to these for your server, you can use those instead.

` // Config $db_user = "db_username"; $db_pass = "db_pass";

// Dump an entire database exec("mysqldump --opt -u$db_user -p$db_pass my_database > backup.sql");

// Dump a table exec("mysqldump --opt -u$db_user -p$db_pass my_database my_table > backup.sql");

// Dump just table rows without structure exec("mysqldump --opt -u$db_user -p$db_pass --no-create-info my_database my_table > backup.sql");

// Dump just table rows with WHERE clause without structure exec("mysqldump --opt -u$db_user -p$db_pass --no-create-info --where=id='1' my_database my_table > backup.sql");

// Restoring from .sql file exec("mysql -u$db_user -p$db_pass my_database < backup.sql"); `
Note. Where the exec() function starts with mysqldump; you could replace it with C:Program FilesMySQLbinmysqldump.exe for example if you are not permitted to copy the two required files from the bin folder.


php / mysql / exec / mysqldump

← Remove File Extension Create A Lockscreen Shortcut in Windows →