MySQL .frm File Format MySQL

Regardless of the storage engine you choose, every MySQL table you create is represented, on disk, by a .frm file, which describes the table's format (i.e. the table definition). The file bears the same name as the table, with a .frm extension. The .frm format is the same on all platforms but in the description of the .frm format that follows, the examples come from tables created under the Linux operating system. First, let's create an example table, using the mysql client: mysql> CREATE TABLE table1 (column1 CHAR(5)) ENGINE=MYISAM COMMENT '*'; Query OK, 0 rows affected (0.00 sec) The .frm file associated with table1 can be located in the directory that represents the database (orschema) to which the table belongs. The datadir variable contains the name of this directory:

MySQL .frm File Format

The DATABASE() function contains the name of the relevant database:

MySQL .frm File Format

Since MySQL stores .frm files in datadir/database_name, it's a simple matter to locate the corresponding
.frm file for table1. For example, within a Linux shell:

You'll see a response like the following:

The .MYD and .MYI files are not our concern here; they are described elsewhere in this MySQL internals
manual. To understand the .frm format, let's look at table1.frm using a hexadecimal-dump utility;
the contents are show below.
hexadecimal-dump utility; the contents

The details shown above might change, especially since there is a transition underway from an old("binary") format to a new ("text based") .frm format. You can confirm that the details are correct by comparing this description with the statements in sql/, create_frm(). The table below explains the meaning of each byte in the hexadecimal dump shown in the above example. The Offset column shows the byte position in the file; Length is the number of bytes; Value is what's in that byte position for that length (remember that storage is "low byte first" so 0010 means 1000!); and Explanation provides a brief explanation of the contents.

meaning of each byte in the hexadecimal dumpmeaning of each byte in the hexadecimal dumpmeaning of each byte in the hexadecimal dumpmeaning of each byte in the hexadecimal dump

The .frm file for a partitioned table contains partition information, in clear text, in addition to the usual table definition details. Let's create a partitioned table and do a hexadecimal dump of its .frm.

The hexadecimal dump from table2 is shown below:

hexadecimal dump from table2

In the example output, notice that position 00001010 and following contains the clear text of the CREATE TABLE ... PARTITION clause and not just the MYISAM engine information, as in table1, which shows the .frm of a non-partitioned table.

Finally, CREATE VIEW also causes creation of a .frm file, but a view .frm bears no resemblance to a base table .frm; it's purely textual. Here's an example of a .frm for a view made with:

Just looking at the text will tell you what it's about. For example let's do another hexadecimal dump; the contents are shown below.

hexadecimal dumphexadecimal dump

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

MySQL Topics