It sounds to me like you are using Debian or Ubuntu if your apache user is www-data. I would NOT recommend trying to change the apache user to anything else -- especially not root as this would likely introduce all kinds of security problems.
Instead, you need to find the directories or files affected by your system command and make those files readable/writeable by www-data. An obvious one is the dir /home/username/Desktop/ which probably belongs to username. Rather than using such an important/critical directory as your desktop directory, i would recommend creating a subdirectory in that folder and assigning read/write/execute permissions on the subfolder to www-data:
sudo mkdir /home/username/Desktop/dump_folder
sudo chown username:www-data /home/username/Desktop/dump_folder
sudo chmod 775 /home/username/Desktop/dump_folder
Since you are specifying the username and password in your system() command, that should sidestep any permissions problems as long as the username and password are correct and have access to the database being dumped. Note that it might present a bit of a security problem if the user www-data has a log file of its command line actions stored on the server because this file (also accessible to any other script run on your web server) would contain the mysql root user and password stored as plain text.