I want to take backup of Xampp database available in /opt/lampp/var/mysql `but I am unable to do it. I used below command
/opt/lampp/htdocs/vivek.s$ sudo mysqldump -u root -p vive.se > 07feb.sql
and
/opt/lampp/htdocs/vivek.s$ sudo mysqldump -h root -u root -p vive.se > 07feb.sql
Result is same
bash: 07feb.sql: Permission denied
Then I used
sudo -s
sudo mysqldump -u root -p vive.se > 07feb.sql
Result is
sudo: mysqldump: command not found
and it created a Empty file named 07feb.sql in /opt/lampp/htdocs/vivek.s
What is wrong while I saw my friend using same command and he got database backup of 95 MB. What should I try.
Thanks
The problem is that you do not have permission to write to
/opt/lampp/htdocs/vivek.s
as your normal user. Runningmysqldump
as root elevates mysqldump (unnecessarily), but the redirection happens with the permissions of the shell - running as your regular user.There's a few workarounds:
sudo -i
orsudo -s
. You should not use sudo to run the next command - mysqldump.Use
tee
:mysqldump -u root -p vive.se | sudo tee 07feb.sql > /dev/null
This will run the process
tee
as root, writing one copy to file, and redirecting stdout to/dev/null
as we don't need it.Another workaround would be to write the backup to a location where your user has write permission, for instance your home directory.