【发布时间】:2011-01-08 05:42:29
【问题描述】:
我有数据库服务器和其他 4 个客户端服务器。
来自客户端服务器的一次连接数超过 600。
它有很多慢查询,这是由于表锁定。
我已将其中一张表更改为 InnoDB,它可以获得更多更新和插入查询。
请帮助我优化数据库。我有一个专门的数据库服务器。
以下是 my.cnf 设置。
[mysqld]
tmpdir=/tmp
open_files_limit=33628
log-slow-queries=/slow-query.txt
long_query_time=1
log-queries-not-using-indexes=1
concurrent_insert=2
old_passwords=1
datadir=/var/lib/mysql
safe-show-database
tmp_table_size = 128M
max_heap_table_size = 128M
query_cache_limit=8M
query_cache_size=128M ## 32MB for every 1GB of RAM
query_cache_type=1
max_user_connections=800
max_connections=800
collation_server=utf8_unicode_ci
character_set_server=utf8
delayed_insert_timeout=40
interactive_timeout=10
wait_timeout=3600
connect_timeout=20
thread_cache_size=128
key_buffer=128M ## 32MB for every 1GB of RAM
join_buffer=1M
max_connect_errors=20
max_allowed_packet=16M
table_cache=400
record_buffer=1M
sort_buffer_size=4M ## 1MB for every 1GB of RAM
read_buffer_size=4M ## 1MB for every 1GB of RAM
read_rnd_buffer_size=4M ## 1MB for every 1GB of RAM
thread_concurrency=8 ## Number of CPUs x 2
myisam_sort_buffer_size=32M
server-id=1
[mysql.server]
user=mysql
[safe_mysqld]
open_files_limit=33628
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysql/mysql.pid
目前我正在使用非持久连接,持久连接可以提高我的性能吗?
【问题讨论】:
-
那个 ini 文件对你没有帮助,杀死你的是你的查询和可能的表设计,而不是数据库本身。
-
日志表查询更像是 7/10 查询。每秒平均查询次数超过 70 次。
标签: php mysql sql query-optimization