How to preload tables into INNODB buffer pool with MySQL?

前端 未结 2 671
野的像风
野的像风 2020-12-12 23:20

I have an e-commerce application that uses MySQL, and I\'d like it to be faster. When a part # is accessed on the website that has been accessed before, the part loads quick

相关标签:
2条回答
  • 2020-12-12 23:44

    This query will return table names in your database, so you don't have to input them manually:

    SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'database name'
    

    Then for each table name force table scan.

    0 讨论(0)
  • 2020-12-12 23:49

    This should give you a list of queries to run ;)

    SELECT 
      CONCAT('SELECT ',MIN(c.COLUMN_NAME),' FROM ',c.TABLE_NAME,' WHERE ',MIN(c.COLUMN_NAME),' IS NOT NULL')
    FROM
      information_schema.COLUMNS AS c
    LEFT JOIN (
      SELECT DISTINCT
        TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME
      FROM
        information_schema.KEY_COLUMN_USAGE
    ) AS k
    USING
      (TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME)
    WHERE
      c.TABLE_SCHEMA = 'yourDatabase'
      AND k.COLUMN_NAME IS NULL
    GROUP BY
      c.TABLE_NAME
    

    You can put it into stored procedure, and go over the resultset with cursor. Create a prepared statement from each row, and execute.

    0 讨论(0)
提交回复
热议问题