8.8.3. How MySQL Opens and Closes Tables
When you execute a
Uptime: 426 Running threads: 1 Questions: 11082
Reloads: 1 Open tables: 12
The
Open tables
MySQL is multi-threaded, so there may be many clients issuing queries for a given table
simultaneously. To minimize the problem with multiple client sessions having different states on the
same table, the table is opened independently by each concurrent session. This uses additional
memory but normally increases performance. With
for the data file for each client that has the table open. (By contrast, the index file descriptor is shared
between all sessions.)
The
table_cache
of files the server keeps open. If you increase one or both of these values, you may run up against
a limit imposed by your operating system on the per-process number of open file descriptors. Many
operating systems permit you to increase the open-files limit, although the method varies widely from
system to system. Consult your operating system documentation to determine whether it is possible to
increase the limit and how to do so.
table_cache
connections, you should have a table cache size of at least
of tables per join in any of the queries which you execute. You must also reserve some extra file
descriptors for temporary tables and files.
Make sure that your operating system can handle the number of open file descriptors implied by
the
table_cache
descriptors and refuse connections, fail to perform queries, and be very unreliable. You also have to
take into account that the
table. You can increase the number of file descriptors available to MySQL using the
[417]
limit
Errors".
The cache of open tables is kept at a level of
can be changed with the
open more tables than this to execute queries.
MySQL closes an unused table and removes it from the table cache under the following circumstances:
• When the cache is full and a thread tries to open a table that is not in the cache.
• When the cache contains more than
longer being used by any threads.
• When a table flushing operation occurs. This happens when someone issues a
statement or executes a
When the table cache fills up, the server uses the following procedure to locate a cache entry to use:
• Tables that are not currently in use are released, beginning with the table least recently used.
• If a new table needs to be opened, but the cache is full and no tables can be released, the cache is
temporarily extended as necessary. When the cache is in a temporarily extended state and a table
goes from a used to unused state, the table is closed and released from the cache.
A
table is opened for each concurrent access. This means the table needs to be opened twice
MyISAM
if two threads access the same table or if a thread accesses the table twice in the same query (for
How MySQL Opens and Closes Tables
mysqladmin status
value of 12 can be somewhat puzzling if you have only six tables.
[498]
and
max_connections
[498]
is related to
max_connections
[498]
setting. If
table_cache
storage engine needs two file descriptors for each unique open
MyISAM
startup option to mysqld. See
--table_cache
mysqladmin flush-tables
command, you should see something like this:
tables, one extra file descriptor is required
MyISAM
[467]
system variables affect the maximum number
[467]. For example, for 200 concurrent running
200 *
[498]
is set too high, MySQL may run out of file
Section C.5.2.18,
[498]
table_cache
[498]
option to mysqld. Note that MySQL may temporarily
[498]
entries and a table in the cache is no
table_cache
or
716
N, where
is the maximum number
N
"'File' Not Found
entries. The default value is 64; this
FLUSH TABLES
mysqladmin refresh
--open-files-
and Similar
command.
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers