First, let me say that mysql seems to be working perfectly on the machine. Still, when I su mysql and ls /var/lib/mysql, I get access denided. When I sudo ls /var/lib/mysql I see the data files corresponding to my database tables, so this is definitely the data folder of mysql.

Shouldn't the mysql user have access to its own data folder? Is the machine misconfigured somehow?

Some more details:

$ sudo ls -la /var/lib/ | grep mysql
drwx------  5 mysql     mysql   4096 2011-06-25 08:05 mysql
$ sudo su mysql
$ ls /var/lib/mysql
ls: cannot open directory /var/lib/mysql: Permission denied
$ sudo ls -la /var | grep lib
drwxr-xr-x 42 root root  4096 2011-03-17 12:03 lib
$ sudo ls -la / | grep var
drwxr-xr-x 14 root root  4096 2010-12-02 19:14 var
  • 4
    The directory /var/lib/mysql should be owned by user mysql with permissions 700. Atleast thats how it is on my box. Also all the files inside are owned by mysql with 700 permissions. I can execute ls fine on my computer. Don't know why it didn't work for you. What do you see when you do sudo ls -la /var/lib/mysql? Is owner mysql and perms 700? – Deepak Mittal Jun 25 '11 at 8:12
  • It's hard to answer "is the machine misconfigured" when you haven't included your configuration in your question. What are the ownership and permissions on that directory and it's parents? What group is your mysql user a part of? – Caleb Jun 25 '11 at 13:33
  • @dpacmittal, @Caleb, added some more details. If I'm reading this correctly then mysql is the owner of /var/lib/mysql, and it should have read rights to all its parents. – ripper234 Jun 26 '11 at 6:16

Your test is somehow faulty. As evidenced by the fact that the daemon is working properly, the mysql user is able to read that folder. As shown by the output of ls, it is properly owned by mysql. If you were really the mysql user, you wouldn't have a problem reading it.

I presume your su failed, probably due to the fact that the mysql user doesn't have a shell. You can check in /etc/passwd, but it is probably set to /bin/true or something liket that, so the su succeeded but promptly exited, then when you ran the ls it just ran as your user. Try sudo -u mysql ls -al /var/lib/mysql instead.

Next time check that you actually are who you think you are by running whoami. This is one reason the current username is often part of PS1 prompts too. If your copy/paste above hasn't been edited, your shell prompt isn't showing you who you are.

  • You could also go through root. Switching from root to any other user doesn't require a password.su then su username. – Faheem Mitha Jun 26 '11 at 8:12
  • @Faheem: That doesn't help this OP's situation at all, in fact it only makes it more confusing to sort out. Suing from root would have a net-zero affect on the outcome if the target user doesn't have a shell. Using the sudo -u construct I suggested allows you to run individual commands as an arbitrary user even if that user doesn't have a shell in /etc/passwd. – Caleb Jun 26 '11 at 20:19
  • @Caleb: Ok, it was merely an observation. It's what I do, and it's convenient. I'm not aware of any downsides. – Faheem Mitha Jun 26 '11 at 21:10
  • @Faheem: The obvious downside is that when (as happened to this guy) it silently fails you end up in a root shell thinking you are in a user shell instead of in a user shell thinking you are in a different user shell. Your imagination can fill in from there, but it's bad form because it leaves you open to all kinds of mistakes that are more serious than they had to be because you had more system privileges than you expected. – Caleb Jun 26 '11 at 21:23
  • @Caleb: Ok, you are probably a better judge than myself of safe practices. Though a) I don't see why it should fail and b) you have that convenient # reminding you. Also, my prompt has the user name. A useful thing, if you don't have it. – Faheem Mitha Jun 26 '11 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.