The best way is to log-in to your cpanel and then go to phpMyAdmin, on the top menu click "export", on the export method option, select sql click go, at the prompt confirm the download. Save your sql backup file on your desktop.
Prgrammatically, don't even bother it is just too slow. I don't know, maybe someone have a faster way of creating back up by way of php that is fast enough for me to get excited.
Server problems, it will be in the hands of your hosting company. Let's just hope they are doing a daily back-up. Otherwise, let's just cross our fingers, and hope that all the data are still there upon recovery. If you are running your own server, the data is located in mysql/data directory. I am not sure how it would look like in linux... let me run my linux box and see..
I am so happy for you.. It is always a good habit to back up database. For people who are just lazy doing it on phpmyadmin panel. You can also do this behind the putty terminal. Assuming that your hosting account has a root access with it or the account is allowed to access through SSH terminal like putty.
Run putty.exe for windows and accessories->terminal on linux. On the terminal prompt type
Give your server an ample time to execute the command, and then open your FTP program like the filezilla. Connect to your site and look for the dataBaseName_dump.dump, download this dump file to your desktop. For linux distros like ubuntu or Zorin Os, this can be done by just opening the terminal and then run the following command
System will ask for your password, type password and then type