How to fix permissions, I accidentally entered “sudo chown -R username /”?
I got the sudo to working again by logging into the Root account however the WordPress website shows a database error and I’m positive it’s because of the wrong permissions now… I can’t seem to connect to the database and I’m not sure which permissions to fix.
I get this error when I try to start the msql:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
Also, I have a snapshot that I have, would that fix my mistake? It’s my last resort if so.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
@csc
You’ll have to forgive me for dropping directly in to the comments instead of re-reading the original on this one. I was following the tags and got to the point about MySQL.
The issue is you ran
chown
on/
and at this point, changing the ownership of the MySQL directory isn’t going to be enough as files that need to be owned byroot
and other users are now setup with ownership by a user that – best case is asudo
user – worst case, is just a normal user (thus software that needsroot
won’t function).Your system won’t function properly in that state. Even if you do manage to get MySQL up and running, something else is very likely to go wrong and you’ll be back in the same situation with a different piece of software.
…
Given the numerous files and directories that were affected by
chown -R user /
, your absolute best bet is going to be deploying another Droplet and building it over – then migrating your site over to it.Note, I’m not saying rebuild from a snapshot (unless that snapshot is before you ran this command), I mean literally start from scratch so that all files and directories are properly owned by their respective users.
I know that’s not what you want to hear right now, but you’re going to spend more time trying to fix the files/directories and their ownership/permissions than you will moving the site over. There’s no way to just undo a command either, so starting from scratch is going to be your best bet.
…
One thing though – don’t beat yourself up over it – we all make mistakes. I’ve made my fair share in the last 16-17 years. Moving forward, I find it best to write your commands in a text editor, and then copy -> paste in to terminal. That way you’re physically looking at the command at least twice before you hit enter.
@hansen
this is what it shows now after running chown root /var/log/btmp
@csc Starting a new thread, since it’s maxed out.
Can you run
tail -100 /var/log/mysql/error.log
because we need to see the lines just before InnoDB complaining about rights.