How to recover mysql folder?

February 18, 2017 154 views
MySQL Ubuntu 16.04

Mysql Not Working. Site Crashed- (Emergency)
After following other steps mentioned in some of the similar Digital Ocean posts, i discovered that my MYSQL folder is not present or that i cannot find it. I want to know how to find it or how to recover the folder to acces my existing DB. It had alot of data.

Associated Droplet: ubuntu-512mb-blr1-01

oops connection problem ! --> Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

That's the error showing everywhere, be it from a terminal or from the browser. We have important information in our databases and we cannot afford to lose them. Please help asap. Our store website is down since the last 48 hours. Perhaps more.

1 Answer


Have you made any modifications to MySQL's configuration? Generally that specific error is caused by changes to the configuration, which are not valid, unless your MySQL directories were in fact removed somehow.

On Ubuntu, your MySQL data directory should be located at /var/lib/mysql. As long as that directory exists, then you should still have your data. If that directory has been removed, without backups, there's no way to restore it.

Quick Tip: Make sure you're regularly backing up your data/databases. If you don't have valid, working backups, there's no way to restore your data.

That said, what you can do is backup that directory -- do this first.

mkdir -p /usr/local/src/mysql
cp -R /var/lib/mysql/* /usr/local/src/mysql

The above creates a backup directory and then copies all files in the MySQL data directory to it, so if something should happen with what we do next, we have a backup copy of your data.

Now, we need to see what errors MySQL is throwing when you try to start MySQL, so go ahead and run:

service mysql restart

Then run this command to grab the last 30 lines from the error log:

tail -30 /var/log/mysql/error.log

Paste that output to a code block as a reply so it's formatted and we can see what's going on. I'd do this before we attempt to remove MySQL and then reinstall.

  • Table status:
    Opened tables: 65
    Open tables: 60
    Open files: 70
    Open streams: 0

    Alarm status:
    Active alarms: 0
    Max used alarms: 0
    Next alarm time: 0

    Memory status:
    Non-mmapped space allocated from system: 12312576
    Number of free chunks: 71
    Number of fastbin blocks: 19
    Number of mmapped regions: 17
    Space in mmapped regions: 49676288
    Maximum total allocated space: 0
    Space available in freed fastbin blocks: 1088
    Total allocated space: 9400496
    Total free space: 2912080
    Top-most, releasable space: 1900576
    Estimated memory (with thread stack): 6257868170218 15:25:23 mysqld_safe A mysqld process already exists
    170218 15:30:44 [Note] /usr/sbin/mysqld: Normal shutdown

    170218 15:30:46 InnoDB: Starting shutdown...
    170218 15:30:47 InnoDB: Shutdown completed; log sequence number 2006213
    170218 15:30:47 [Note] /usr/sbin/mysqld: Shutdown complete

    170218 15:30:47 mysqld_safe mysqld from pid file /var/run/mysqld/ ended

    Thats the whole set of lines.

Have another answer? Share your knowledge.