Openfire服務器MySQL優化:mysql
[root@iZ28g4ctd7tZ ~]# mysql -u root -p XXXXXsql
mysql> show processlist;vim
+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+緩存
| Id | User | Host | db | Command | Time | State | Info |服務器
+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+less
| 1 | event_scheduler | localhost | NULL | Daemon | 51497 | Waiting for next activation | NULL |socket
| 16069885 | xx_xxx_user | 10.164.13.209:48184 | XXXXX | Sleep | 0 | | NULL |tcp
| 16069886 | xx_xxx_user | 10.164.13.209:48185 | XXXXX | Sleep | 0 | | NULL |memcached
| 16069887 | xx_xxx_user | 10.164.13.209:48186 | XXXXX | Sleep | 0 | | NULL |函數
| 16069888 | xx_xxx_user | 10.164.13.209:48187 | XXXXX | Sleep | 0 | | NULL |
| 16069889 | xx_xxx_user | 10.164.13.209:48188 | XXXXX | Sleep | 0 | | NULL |
......
| 16071110 | xx_xxx_user | 10.164.13.209:48520 | XXXXX | Sleep | 3 | | NULL |
| 16358232 | root | localhost | XXXXX | Query | 0 | NULL | show processlist |
+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+
118 rows in set (0.00 sec)
mysql> show variables like '%timeout';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 100 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 100 |
+----------------------------+----------+
10 rows in set (0.00 sec)
mysql> show global variables like '%timeout';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 100 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 100 |
+----------------------------+----------+
10 rows in set (0.00 sec)
mysql> set global interactive_timeout=100;
mysql> set global wait_timeout=100;
若是修改interactive_timeout的話wait_timeout也會跟着變,而只修改wait_timeout是不生效的。
[root@iZ28g4ctd7tZ ~]# vim /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld_safe]
socket = /data/mysql/mysql.sock
nice = 0
[mysqld]
#datadir=/data/mysql/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
# 默認端口
port = 3306
datadir = /data/mysql/data/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
# 避免MySQL的外部鎖定,減小出錯概率加強穩定性
skip-external-locking
# 設置mysql服務器的字符集
character-set-server = utf8
# 默認存儲引擎
default-storage-engine = INNODB
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 0.0.0.0
skip-name-resolve
# UDF自定義函數如有用到須要打開。後續memcached會用到UDF
log_bin_trust_function_creators = 1
# 用到了事件,應該打開
event_scheduler = 1
# Error log - should be very few entries.
# log_error = /data/mysql/log/error.log
key_buffer = 16M
# MYISAM存儲引擎的索引緩衝區的大小
key_buffer_size = 16M
# 聯合查詢操做所能使用的緩衝區大小
join_buffer_size = 4M
# 用來控制其通訊緩衝區的最大長度
max_allowed_packet = 16M
# 指定MySQL容許的最大鏈接進程數。若是常常出現Too Many Connections的錯誤提 示,則須要增大該參數值。默認值是151,這裏設爲500。根據實際狀況再行調整
max_connections = 500
# 最大鏈接錯誤數
max_connect_errors = 10000
# 緩存可重用的線程數
table_open_cache = 4096
# 查詢排序時所能使用的緩衝區大小
sort_buffer_size = 4M
# 每一個進行一個順序掃描的線程爲其掃描的每張表分配這個大小的一個緩衝區,若作不少順序掃描,增長該值。
read_buffer_size = 4M
# 隨機讀緩存區,mysql排序查詢時,先掃描該緩衝避免磁盤搜索
read_rnd_buffer_size = 8M
# 開啓查詢緩存
query_cache_type = 1
# 指定MySQL查詢緩衝區的大小
query_cache_size = 256M
# 單個查詢能用緩衝區大小
query_cache_limit = 2M
# 指定分配緩衝區空間的最小單位,缺省爲4K
query_cache_min_res_unit = 4K
# 內存表大小,該值用來計算內存表的最大行數
max_heap_table_size = 32M
# 指定mysql緩存的內存大小,默認16M
tmp_table_size = 32M
# 臨時中止響應新請求前在短期內能夠堆起多少請求,也就是說,若是MySql的鏈接數據達到max_connections時,新來的請求將會被存在堆棧中,以等待某一鏈接釋放資源,
# 該堆棧的數量即back_log,若是等待鏈接的數量超過back_log,將不被授予鏈接資源。back_log值不能超過TCP/IP鏈接的偵聽隊列的大小。若超過則無效,
# 查看當前系統的TCP/IP鏈接的偵聽隊列的大小命令:cat /proc/sys/net/ipv4/tcp_max_syn_backlog目前系統爲1024。對於Linux系統推薦設置爲小於512的整數。
# 每一個鏈接256kb,佔用:125M
back_log = 500
# 指定一個請求的最大鏈接時間,超時時間,能夠避免攻擊。對於4GB左右內存的服務器能夠設置爲5-10
wait_timeout = 604800
# 服務器在關閉它前在一個交互鏈接上等待行動的秒數
interactive_timeout = 604800
# 該參數取值爲服務器邏輯CPU數量×2,默認8
# 該參數在5.6.1版本後被放棄了
thread_concurrency = 16
thread_stack = 512K
thread_cache_size = 64
myisam-recover = BACKUP
# 記錄慢查詢語句,路徑根據實際
log_slow_queries = /data/mysql/log/mysql-slow.log
# 設定慢查詢的時間
long_query_time = 2
# 記錄未用索引的慢查詢
log-queries-not-using-indexes
# 開啓二進制日誌earcs-bin爲日誌文件前綴 basename
log_bin = /data/mysql/log/earcs-bin.log
# 設置日誌的有效期爲10天.
expire_logs_days = 2
max_binlog_size = 100M
# 打開文件數
open_files_limit = 10240
# 控制日誌刷新到硬盤的時機
innodb_flush_log_at_trx_commit = 0
# on表示啓用單表空間,減小共享表空間維護成本,減小空閒磁盤空間釋放的壓力
innodb_file_per_table = 1
# 設置事務隔離級別
transaction-isolation = READ-COMMITTED
# 二進制日誌格式
binlog-format = MIXED
# 官方建議在一個32位的系統中,要設置小於2G。
innodb_buffer_pool_size = 10G
# 控制日誌刷新到硬盤的時機
innodb_flush_log_at_trx_commit = 0
# 須要根據寫負載的頻度以及大事務的多少,動態調整。
innodb_log_buffer_size = 8M
# 在日誌組中每一個日誌文件的大小
innodb_log_file_size = 512M
# 這個參數在5.6.3版本之後會被棄用。
innodb_additional_mem_pool_size = 100M
# 提升mysql速度的,禁止DNS緩存
skip-host-cache
[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysqld/mysqld.pid