How does MySQL store data

前端 未结 4 1797
-上瘾入骨i
-上瘾入骨i 2020-12-15 03:26

I looked around Goole but didn\'t find any good answer. Does it store the data in one big file? What methods does it use to make data access quicker than just reading and wr

4条回答
  •  感情败类
    2020-12-15 04:09

    This question is a bit old but I decided to answer it anyway since I have been doing some digging on the same. My answer is based on the linux file system. Basically mySQL stores data in files in your hard disk. It stores the files in a specific directory that has the system variable "datadir". Opening a mysql console and running the following command will tell you exactly where the folder is located.

    mysql>  SHOW VARIABLES LIKE 'datadir';
    +---------------+-----------------+
    | Variable_name | Value           |
    +---------------+-----------------+
    | datadir       | /var/lib/mysql/ |
    +---------------+-----------------+
    1 row in set (0.01 sec)
    

    As you can see from the above command, my "datadir" was located in /var/lib/mysql/. The location of the "datadir" may vary in different systems. The directory contains folders and some configuration files. Each folder represents a mysql database and contains files with data for that specific database. below is a screenshot of the "datadir" directory in my system.

    Each folder in the directory represents a MySQL database. Each database folder contains files that represent the tables in that database. There are two files for each table, one with a .frm extension and the other with a .idb extension. See screenshot below.

    The .frm table file stores the table's format. Details: MySQL .frm File Format

    The .ibd file stores the table's data. Details: InnoDB File-Per-Table Tablespaces

    That’s it folks! I hope I helped someone.

提交回复
热议问题