In order to execute mysqlbackup I have to execute it as root.

Here's the example when I execute it as normal user:

mysqlbackup --compress --user=root --socket=/var/lib/mysql/mysql.sock --backup-dir=/home/user/backup backup
MySQL Enterprise Backup version 3.12.2 Linux-2.6.32-400.37.11.el6uek.i686-i686 [2016/01/19] 
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 mysqlbackup --compress --user=root --socket=/var/lib/mysql/mysql.sock 
        --backup-dir=/home/user/backup backup 

 mysqlbackup: INFO: 
 mysqlbackup: INFO: MySQL server version is '5.5.44-MariaDB'.
 mysqlbackup: INFO: Got some server configuration information from running server.

IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'backup' run mysqlbackup
           prints "mysqlbackup completed OK!".

160226 08:30:02 mysqlbackup: INFO: MEB logfile created at /home/user/backup/meta/MEB_2016-02-26.08-30-02_compress_backup.log

 mysqlbackup: ERROR: Opening of file /var/lib/mysql/ibdata1 failed. Error code: 13, Permission denied

which leads to Permission denied, so I tried to execute it with sudo and I get this:

 sudo mysqlbackup
[sudo] password for user: 
sudo: mysqlbackup: command not found

But when I execute it as a root I don't have any problems...

my user is inside of the sudoers file just so you know and I can also execute other commands with sudo with no problems, but in this case my question is, why I can't execute it with sudo and how I can be able to execute it without recurring to sudo -i to get the root environment?

Note: They both have the same $PATH

[root@localhost ~]# echo $PATH
[root@localhost ~]# exit
[user@localhost backup]$ echo $PATH
  • sudo creates a minimal operating environment, in which the PATH variable doesn't contain as many directories as, when you login as root in an interactive session. You need to specify the path to mysqlbackup executable explicitly, to overcome this hurdle. While logged in as root, run which mysqlbackup to get the full path name if need be
    – MelBurslan
    Apr 14, 2016 at 20:37
  • 1
    This is potentially configuration-specific. You should say what distribution and version you are using.
    – sourcejedi
    Apr 14, 2016 at 20:51
  • @sourcejedi Centos 7
    – VaTo
    Apr 15, 2016 at 0:51

2 Answers 2


Probably secure_path is set in /etc/sudoers. The path shown by which mysqlbackup is not included there, but it is shown in echo $PATH when run as your user or from a root login, right? It does seem odd though.


So the reason that you're backup is failing as a normal user is because the libdata file that mysqlbackup is attempting to copy/backup is owned by a different user (more than likely, 'mysql') or a privileged user. So, running mysqlbackup as an elevated user is probably the right choice here as you're attempting to do.

I surmise that the reason you aren't able to find mysqlbackup as an elevated user is your PATH environment not being set properly or set at all. Am I right to assume that you can't do something like:

sudo /usr/bin/mysqldump --compr....

If you can then just make sure to run the command with the absolute path to mysqldump. If that doesn't work because of how sudo is configured, then you'll need to try a different tactic like.

PATH=/usr/bin sudo mysqlbackup --compress ...

Now if that works, great. However, it's not very nice for future command line use. You could create an alias to run mysqlbackup in the future so that you don't need to specify the PATH in the command line for future use:

For bash:

(for other shells like zsh, you'll need to read the docs on how to set an alias)

echo 'alias mysqlbackup="PATH=/usr/bin sudo mysqlbackup"' >> ~/.bashrc

...which could be invoked, after sourcing the .bashrc file (logout and login is sufficient, or sourcing the file IE . ~/.bashrc), in the future by simply running:

mysqlbackup --compress...

Let's say none of that works, though. You'll probably need to get the administrator of the machine to change your sudo permissions for mysqlbackup to either include the proper PATH or to specify an absolute path to mysqlbackup in the sudoers file for your ability to call it from the shell when executing sudo.

Hopefully that helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .