- 首先生產環境不建議這樣做,只是為了測試
-
導致統計信息不准確的原因是什么呢?其實是MySQL 8.0為了提高information_schema的查詢效率,將視圖tables和statistics里面的統計信息緩存起來,緩存過期時間由參數information_schema_stats_expiry決定,默認為86400s;如果想獲取最新的統計信息,可以通過如下兩種方式:
(1)analyze table進行表分析
(2)設置information_schema_stats_expiry=0
- 所以針對以上情況
use mysql; SET GLOBAL information_schema_stats_expiry=0; SET @@GLOBAL.information_schema_stats_expiry=0; SET SESSION information_schema_stats_expiry=0; SET @@SESSION.information_schema_stats_expiry=0; use information_schema; -- select sum(table_rows) from tables where TABLE_SCHEMA = "limesurvey" order by table_rows asc; select table_name,table_rows from tables where TABLE_SCHEMA = 'limesurvey' and table_rows>0 order by table_name ;