Question

How to fix permissions, I accidentally entered "sudo chown -R username /"?

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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Accepted Answer

@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 by root and other users are now setup with ownership by a user that – best case is a sudo user – worst case, is just a normal user (thus software that needs root 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.

This comment has been deleted

    @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.

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.