1

I have a lot of tables in my database, almost 1,000. Most of them I am not using now.

Is there any way to know from the information schema tables when I have last used my tables?

3

No, that information is not available on INFORMATION_SCHEMA (it only stores metadata).

There are several options that I can recommend you:

  • The user stats plugin from Google: after installed and enabled, it will not tell you the last time a table was accessed, but it will tell you how many times it was
  • Using the slow log: you can activate the slow log and set long_query_time = 0 (be careful of the extra overhead and disk space and then analyze per table used, so you can detect the last time it was used. Tools like pt-query-digest --review aggregate by query, not by table, but they may be useful to look for specific queries.
  • With an audit plugin you can fine-tune what you register better than with the slow log, by activating it only for certain queries or objects.
  • The performance schema can gather information about everything, but you may need MySQL 5.6 and the configuration can be a bit cumbersome

All of them will tell you information since the point you activate them, and not past information. UNIX atime is very unreliable for access time, but you may also want to give that a try, depending on the engine.

  • What I want is to check whether a table in my database is being used,need not be updated read itself is to be notified.. – Arun Bertil Sep 17 '14 at 12:29
0

Try this query

SELECT * FROM
(
    SELECT
        table_name,
        IFNULL(update_time,create_time) LastTimeTouched
    FROM
        information_schema.tables
    WHERE
        table_schema = 'mydb'
) A
ORDER BY LastTimeTouched LIMIT 20;
  • 2
    That will only show the time of creation (update time is in general not reliable, you can update a table with that being NULL), and it will not show the last table read. Please check the manual: dev.mysql.com/doc/refman/5.0/en/show-table-status.html – jynus Sep 17 '14 at 10:39
  • @jynus check my updated answer – Prashant Tapase Sep 17 '14 at 10:40
  • And this is why your query is useless: pastebin.com/KSTnSbLx – jynus Sep 17 '14 at 10:46
  • @jynus : not getting. It is showing datetime of last used table – Prashant Tapase Sep 17 '14 at 10:51
  • really? I update the table and it is still telling me yesterday's time? Please read the manual link I told you. Even if it worked, that doesn't, it wouldn't show the last access time. – jynus Sep 17 '14 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.