标签:
Openfire服务器MySQL优化:
[root@iZ28g4ctd7tZ ~]# mysql -u root -p XXXXX
mysql> show processlist;
+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+
| 1 | event_scheduler | localhost | NULL | Daemon | 51497 | Waiting for next activation | NULL |
| 16069885 | xx_xxx_user | 10.164.13.209:48184 | XXXXX | Sleep | 0 | | NULL |
| 16069886 | xx_xxx_user | 10.164.13.209:48185 | XXXXX | Sleep | 0 | | NULL |
| 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
标签:
原文地址:http://www.cnblogs.com/huazai8204/p/5799646.html