What Is a Database Catalog?
The database directory is where the database server stores data files, including not only files about tables, but also data files and server option files.
- The location of the default database is compiled in the server.
- If you are installing MySQL in a source distribution, the typical default location may be / usr / local / var;
- / Usr / local / mysql / data if MySQL is installed in a binary distribution;
- Install in RPM file as / var / lib / mysql.
- For distribution on the windwos platform, the location is BASEDIR \ data
- The location of the data directory can be explicitly specified when starting the server with --datadir = / path / to / dir. This option is useful if you want to place the data directory somewhere other than the default.
- Taking the MySQL database as an example, the MySQL data directory contains all the data directories managed by the server. These files are organized into a tree structure and are directly implemented by using the Unix or Windows file system hierarchy.
Each database corresponds to a directory under the data directory.
The tables in a database correspond to the files in the data directory.
The data directory also contains several status files generated by the server, such as log files. These files provide important information about the operation of the server. It is valuable for management, especially when trying to determine the cause of a problem. For example, if a particular query kills the server, you can identify the troubled query by examining the log file. [1]
- Each table in the database exists as three files in the database directory: a format (description) file, a data file, and an index file. The base name of each file is the table name, and the extension indicates the type of the file. The extensions are shown in Table 1. The data and index file extension indicates whether the table uses an older ISAM index or a newer MyISAM index.
- When the ALTER TABLE statement is issued, the server re-encodes tbl_name.frm and modifies the contents of the data and index files to reflect the structural changes indicated by the statement. The same is true for CREATE and DROP INDEX, because the server considers them to be equivalent to ALTER TABLE statements. DROP TABLE deletes three files representing the table.
- Although you can delete a table by deleting the three files in the database catalog that correspond to a table, you cannot manually create or alter a table. For example, if my_db is the current database, DROP TABLE my_tbl is roughly equivalent to the following command:
- The output from SHOW TABLES my_db is exactly a list of the base names of the .frm files in the my_db database directory. Some database systems maintain an entry that lists all tables in the database. But MySQL does not do this because there is no need, this "registration" is implicit in the structure of the data directory. [1]