MySQL變數查詢與設定
阿新 • • 發佈:2021-07-28
變數檢視與設定 mysql> show variables\G; mysql> show variables like "變數名"; mysql> set global 變數名=值; 檢視最大連線數 mysql> show variables like "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+ 設定最大連線數 mysql> set global max_connections=1000; 重新整理連線數 mysql> flush status; 檢視連線超時 mysql> show variables like "connect_timeout"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | connect_timeout | 10 | +-----------------+-------+ 設定連線超時 mysql> set global connect_timeout=5; 檢視執行緒狀態 mysql> show status like "Threads%"; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 1 | | Threads_connected | 1 | | Threads_created | 2 | | Threads_running | 1 | +-------------------+-------+ 檢視連線程序 mysql> show processlist; +----+------+-----------+------+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+----------+------------------+ | 8 | root | localhost | NULL | Query | 0 | starting | show processlist | +----+------+-----------+------+---------+------+----------+------------------+ 檢視快取執行緒數量 mysql> show variables like "thread_cache_size"; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | thread_cache_size | 9 | +-------------------+-------+ 檢視執行緒緩衝開啟表的數量 mysql> show variables like "table_open_cache"; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | table_open_cache | 2000 | +------------------+-------+ 檢視用於MyISAM引擎的關鍵索引快取大小 mysql> show variables like "key_buffer_size"; +-----------------+---------+ | Variable_name | Value | +-----------------+---------+ | key_buffer_size | 8388608 | +-----------------+---------+ 檢視查詢快取的一些引數 mysql> show variables like "%query_cache%"; +------------------------------+---------+ | Variable_name | Value | +------------------------------+---------+ | have_query_cache | YES | | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 1048576 | | query_cache_type | OFF | | query_cache_wlock_invalidate | OFF | +------------------------------+---------+ 其他日誌引數設定 錯誤日誌 log_error[=檔名] //不指定為預設檔名 查詢日誌 general_log //啟用日誌 general_log-file=檔名 //不指定為預設檔名 慢查詢日誌 slow_query_log //啟用日誌 slow_query_log_file=檔名 //不指定為預設檔名 long-query_time=超時時間 //指定超時時間預設為10秒 log_queries_not_using_indexes=1 //記錄未使用索引的sql查詢