Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was trying to install homebrew and very very stupidly did this:

sudo chown -R $USER /usr/local

The Homebrew instructions say to do this and I'm not much of a sysadmin so I took their word for it. Lesson learned (although I wouldn't really know how to test this...seems like an "undo" script would be super valuable here)

Anyway, what is done is done, but now I get this error:

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 548
Server version: 5.1.33 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)

I tried chown-ing back to root with no avail. Does anyone know how I can fix this without reinstalling mysql? Optionally, if I have to reinstall mysql, how can I dump my databases without access to the command line so I don't lose all of my data.


share|improve this question
do you know were you database files are kept .. it more likely that the user 'mysql' needs to own the files not root although they normally would be kept in /usr/local... so i can't imagine why that would effect it at all. – Derek Organ Jun 9 '10 at 15:49
up vote 0 down vote accepted

Find mysql's data directory, and chown that to MySQL's user (typically mysql:mysql)...

share|improve this answer

Determine what user mysql is running as (I'd use ps aux |grep mysql, but your flags to ps might differ), find where mysql is installed (mine shows in the ps results as --datadir=/usr/local/mysql/data, but you might need your screen to be wide enough so it's not truncating the command), and then change the ownership back to the correct user.

share|improve this answer
$ cd /usr/lcoal/mysql/

$ ls -l

$ sudo -R chown mysql:mysql data/

data/ is a directory under /usr/local/mysql/ which contains all the database.

Now do mysql -u user -p password. You can access your database

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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