How to backup the mysql database and download it as a .sql file by using PHP Codes
Use phpmyadmin
Edit:
You can use shell_exec to execute this command
mysqldump -u username -p password database > file
This will generate a dump file,and then redirect user to this generated file.