How to recover mysql folder?

Posted February 18, 2017 6.4k views
MySQLUbuntu 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.

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.

Submit an Answer
2 answers


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.

Hi, I have a similar problem and I have followed the steps listed above and here is the print out from the error log

2019-04-10T13:46:51.372508Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2019-04-10T13:46:51.372512Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2019-04-10T13:46:51.372517Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2019-04-10T13:46:51.372521Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2019-04-10T13:46:51.372526Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2019-04-10T13:46:51.372531Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-04-10T13:46:51.372535Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-04-10T13:46:51.372539Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-04-10T13:46:51.372544Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-04-10T13:46:51.372548Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-04-10T13:46:51.372552Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-04-10T13:46:51.372557Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2019-04-10T13:46:51.372561Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2019-04-10T13:46:51.372565Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2019-04-10T13:46:51.372570Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2019-04-10T13:46:51.372573Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2019-04-10T13:46:51.372578Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2019-04-10T13:46:51.372582Z 0 [Note] Shutting down plugin 'InnoDB'
2019-04-10T13:46:51.372634Z 0 [Note] InnoDB: FTS optimize thread exiting.
2019-04-10T13:46:51.372757Z 0 [Note] InnoDB: Starting shutdown...
2019-04-10T13:46:51.473037Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-04-10T13:46:51.473708Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 190410 13:46:51
2019-04-10T13:46:52.482276Z 0 [Note] InnoDB: Shutdown completed; log sequence number 4825347390
2019-04-10T13:46:52.484340Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-04-10T13:46:52.484367Z 0 [Note] Shutting down plugin 'MEMORY'
2019-04-10T13:46:52.484376Z 0 [Note] Shutting down plugin 'sha256_password'
2019-04-10T13:46:52.484381Z 0 [Note] Shutting down plugin 'mysql_native_password'
2019-04-10T13:46:52.484541Z 0 [Note] Shutting down plugin 'binlog'
2019-04-10T13:46:52.484917Z 0 [Note] /usr/sbin/mysqld: Shutdown complete