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.

Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • WK

    Thanks for the help!

  • cp

    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

    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

  • http://perlino.blogspot.com Michael Ivanchenko

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

    • http://perlino.blogspot.com Michael Ivanchenko

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

  • Nimesh

    Thanx alot. this article really helped me…

  • Piyush

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

  • Muthu Ananth

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

  • http://slatebalapa.wordpress.com venkrao

    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 ~]#
    
  • Michael

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

  • Pinguim

    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

  • Karthikeyan

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

  • http://www.travelcentrictechnology.com rajeshkannan

    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

    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

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

    • damayanthi
       Thank you very much.  your answere was very useful.
    • ammy

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

      • ammy

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

    • Hunain

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

  • Osias

    It really helped. Thanks a lot!

  • Paul

    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 .

  • Bob

    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?

  • http://www.sanjayrnath.blogspot.com Sanjay R Nath

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

  • Kaustav

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

  • Pingback: How to calculate the MySQL database size | MySQL()