1

The following commands work as expected except for the mysqldump command:

/var/www$ sudo mount -t ext4 /dev/sda11 /mnt
/var/www$ cd /mnt
/mnt$ sudo mkdir blabla
/mnt$ ls -la
drwxr-xr-x  5 root root  4096 apr  1 19:24 .
drwxr-xr-x 23 root root  4096 mrt 14 13:39 ..
drwxr-xr-x  2 root root  4096 apr  1 19:24 blabla
/mnt$ cd /var/www
/var/www$ sudo mysqldump -u root -p --databases drupal10 --hex-blob > /mnt/drupal10.sql;
**bash: /mnt/drupal10.sql: Permission denied**

It seems that additional sudo privileges are required to perform the redirect part in the mysqldump command. Any idea how to solve? Thanks

terdon
  • 242,166
jwa
  • 13
  • The issue is that the redirection (>) is not part of the sudo command, so that is being run as your regular user who doesn't have write access to the file. See the answers to the duplicate questions for workarounds. In your case, you probably want mysqldump -u root -p --databases drupal10 --hex-blob | sudo tee /mnt/drupal10.sql. – terdon Apr 01 '23 at 18:10
  • Thanks for your information. Using tee, the mysqldump command works fine when running from within terminal. I'm using this command : sudo mysqldump --defaults-extra-file=/mnt/./.sql/mysqldump.cnf --databases drupal10 --hex-blob | sudo tee /mnt/drupal10/20230403_drupal10.sql When running this command from within a bash script it ends up with next 3 lines and the .sql file is not written. /!40000 ALTER TABLE watchdog ENABLE KEYS /; UNLOCK TABLES; mysqldump: Got error: 1049: Unknown database '|' when selecting the database – jwa Apr 03 '23 at 18:15
  • Can you please ask a new question about that? It sounds like you might not be quoting the commands right since something is reading the | as a database name. We would have to see the exact script and also know exactly how you run it (sh script? bash script? making it executable and running ./script? something else?) to understand what the issue is. – terdon Apr 03 '23 at 18:26

0 Answers0