Where is MySQL database stored

All MySQL databases are stored in corresponding directories inside a MySQL DATADIR directory, which is specified in a configuration. E.g. myExampleDB’s files would be stored inside ‘$DATADIR/myExampleDB’ directory.

If you want to get MySQL datadir location and you have access to MySQL you can simply execute the following SQL query:

mysql> select @@datadir;
| @@datadir |
| /var/db/mysql/ |
1 row in set (0.00 sec)

And according to this result, database files would be stored inside /var/db/mysql/%DB_NAME% directory.

If you don’t have connection to a MySQL, but have an access to the server where MySQL is running then you should check datadir option in process arguments

$ ps -aux | grep mysql
mysql 93562 7:50.38 mysqld –basedir=/usr/local/mysql –datadir=/var/db/mysql –user=mysql –log-error=/var/db/mysql/server.err –pid-file=/var/db/mysql/server.pid

In Windows Vista, Windows 7, Windows 8, Windows Server 2008, and newer DATADIR is by default

C:\ProgramData\MySQL\MySQL Server %VERSION%\

Leave a Reply