Where does MySQL/MariaDB store database data files on Linux or Unix?

; Date: Tue Aug 08 2017

Tags: MySQL »»»» MariaDB

You launch the database server, give it a bunch of data to store, do you need to know where the data files are located? If MySQL or MariaDB does its job properly, the server just runs and runs with no need for further maintenance. But of course, software being software you need to do a bit more. For example, if the system crashes you might need to do a low-level recovery of the databases as I had to do - How to restore a MySQL database and tables from .frm .ibd or .myd raw database files

For various reasons you do need to know where MySQL/MariaDB stores its data files. It's not that hard to locate, and with a little change to the configuration file you can even change that location.

Try this:

$ mysqladmin -u root  -p variables | grep datadir
Enter password:
| datadir     | /var/lib/mysql/ |

The variables command lets you access all kinds of important status indicators from MySQL. It's worth your time exploring it further.

A similar approach is to grep the information from the MySQL/MariaDB configuration file

$ grep datadir /etc/my.cnf

The location for the configuration file on your machine may be different.

This file contains all the settings for your MySQL or MariaDB server. To change anything requires editing this file and then restarting the server.

For more information, see: (dev.mysql.com) https://dev.mysql.com/doc/refman/5.7/en/option-files.html

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.