Main Tutorials

Where does MySQL stored the data in my harddisk?

Here i provide a simple user guide to find out where does MySQL database stored the data in our hard disk, both in Windows and Linux.

Windows

1) Locate the my.ini, which store in the MySQL installation folder.

For Example,

C:\Program Files\MySQL\MySQL Server 5.1\my.ini

2) Open the “my.ini” with our favor text editor.

#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.1/"

#Path to the database root
datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/"

Find the “datadir”, this is the where does MySQL stored the data in Windows.

Linux

1) Locate the my.cnf with the find / -name my.cnf command.


yongmo@myserver:~$ find / -name my.cnf
find: /home/lost+found: Permission denied
find: /lost+found: Permission denied
/etc/mysql/my.cnf

2) viewthe my.cnf file cat /etc/mysql/my.cnf


yongmo@myserver:~$ cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
[mysqld]
#
# * Basic Settings
#
user   = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port   = 3306
basedir  = /usr
datadir  = /var/lib/mysql
tmpdir  = /tmp
language = /usr/share/mysql/english
skip-external-locking

3) Find the “datadir”, this is where does MySQL stored the data in Linux system.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
29 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Michael
11 years ago

Hello, I’m using MySQL 5 on Windows 7 and my database was stored here : C:\ProgramData\MySQL\MySQL Server 5.5\data

Pinguim
11 years ago

Hello,

I found the post usefull, but the information I am searching is how can I alocate diferents databases in diferents path? with the same mysql instance?

thanks

Jim
5 years ago

I am not a computer tech, but using MacBook pro, Safari, opening a website I get the following error: Replace Query: 1114: The table ‘swsessions’ is full in ./__swift/library/Database/class.SWIFT_Database.php:1110. Any help as to how to fix the problem appreciated. I recently did a maintenance clean up on my computer and may have deleted something in error.

Rudresh
10 years ago

where i can see the query executed from JPA in MySQL, How to log the queries to FILE

cp
10 years ago

Hi
Can you explain why mySQL Administrator reports a db index & data of 22MB but the “datadir” is only a series of files of 10KB and the are all *frm files

Qibin
10 years ago

On my file it says:

# These are commonly set, remove the # and set as required.
# basedir = …..
# datadir = …..
# port = …..
# server_id = …..

Do you know where is it commonly set to be?

BTW, I am using the community edition. Thanks

Michael Ivanchenko
10 years ago

On Linux:
find / -name my.cnf 2>/dev/null | xargs cat | grep ‘datadir’

Michael Ivanchenko
10 years ago

find / -name my.cnf 2>/dev/null | xargs grep ‘datadir’

Nimesh
10 years ago

Thanx alot. this article really helped me…

Piyush
10 years ago

Yes I found mine,
Does it work if we copy the database folder and use it in different system??

Muthu Ananth
11 years ago

Please let me know, where I can find in mac system

venkrao
11 years ago

On Linux, perhaps, the following can help (I mean, if the server is already running)

–datadir=/var/lib/mysql

[root@myhost ~]# ps -ef | grep mysql
root     29632     1  0 15:33 pts/13   00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
mysql    29692 29632  0 15:33 pts/13   00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
root     29729 27270  0 15:35 pts/13   00:00:00 grep mysql
[root@myhost ~]#
Karthikeyan
11 years ago

Is mysql server stored all data in flat file structure ?, please share it.

rajeshkannan
11 years ago

Hi this is rajeshkannan i am new to java with mysql.
i am using a server which has database name: redmine_wrk
There is a table name attachments in that database.Which has encrypted file path column.
I dont know the key for that but i know the path from which i need to download the file.
But i don’t know how to download file its in path: /var/www/html/redmine/files
its very urgent can any one please help me .

Thanks in advance

sathish kumar
11 years ago

hey this is is of no use I think. Since then I copied the database from the location which you have intimidated and pasted it on another computer which has same mysql location. The positive side is that it shows the database and the tables in query browser but when I open the table it shows “got error 1 from storage engine error no 1030”

rveach
12 years ago

For Windows 7, it actually stored the ini into:
C:\ProgramData\MySQL
and not into
C:\Program Files\MySQL

Leo
9 years ago
Reply to  rveach

Thankyou – just saved me a massive headache recovering data from an old hard-drive – could not figure out where my MySQL data files had gone and there they are.

Hunain
11 years ago
Reply to  rveach

thanks man !!! u r a life saver !!

ammy
11 years ago
Reply to  rveach

hey,
i made a php script to copy data from mysql to notepad in csv format.
where does it store in my computer.

ammy
11 years ago
Reply to  ammy

also i didn’t find C:\ProgramData\MySQL path in my C drive.

damayanthi
11 years ago
Reply to  rveach
 Thank you very much.  your answere was very useful.
Osias
12 years ago

It really helped. Thanks a lot!

Paul
12 years ago

However, some storage engine can specify its own data file . i.e,innodb-data-file-path.
By default,the table definitins and data are all located in datadir .

Sanjay R Nath
12 years ago

Thanx in tons !!!!!!!!
I was searching the whole net for hours to find my database destination!~!
gr88 work

Kaustav
13 years ago

Thanks. really helpful article to view my tables and other data that MySQL stores in my hard-disk.

Joms
7 years ago

You save me man!.

Kudos! Thank you!

MagBlom
9 years ago

In your HARD disk?

WK
10 years ago

Thanks for the help!

Bob
12 years ago

Thanks, but the files do not seem to grow as I add more data to the tables – So is the data really there or are they just the table definitions?