PDA

查看完整版本 : 对MySQL发掘性能


Tony
2004-05-13, 09:35 PM
转自:http://bbs.et8.net/bbs/showthread.php?t=93120&highlight=mysql
编译
基于gcc2
CC=gcc CFLAGS="-mcpu=pentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-mcpu=pentiumpro -felide-constructors" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --without-debug --with-client-ldflags=-all-static
基于gcc3
CC=gcc3 CFLAGS="-mcpu=pentiumpro" CXX=g++3 CXXFLAGS="-felide-constructors -mcpu=pentiumpro" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --without-bench --with-client-ldflags=-all-static
使用gmake代替make
使用gmake install-strip安装
以上为编译的优化

MySQL的配置
my.cnf
my.cnf,在mysql的安装目录share/mysql/下有几个范例,选一个适合自己的
另外还要修改一下my.cnf
skip-locking
#log-bin
#去掉log,提高性能
server-id = 1
skip-innodb
skip-bdb
#如果不用到bdb,innodb数据表,去掉bdb,innodb支持,节省内存
set-variable = thread_concurrency=4
#设置为你的cpu数目x2,例如,只有一个cpu,那么thread_concurrency=2
#有一个cpu,那么thread_concurrency=4
将你的表转换为MYISAM形式
另外,如果你不怕是用测试版,可以用mysql4来代替mysql3,性能会有提升的

mysql,尽量使用socket来连接,因为使用tcp/ip会降低速度,增大系统开销
对于一个跑着httpd的系统,如果内存不大(512M)的mysql server
可以这样配置my.cnf
set-variable = max_connections=500
set-variable = key_buffer=32M
set-variable = max_allowed_packet=1M
set-variable = table_cache=64
set-variable = sort_buffer=2M
set-variable = record_buffer=1M
set-variable = myisam_sort_buffer_size=16M
skip-innodb
skip-bdb
#log-bin

而对于主要是mysql应用的,而且内存至少1G,可以试用这个配置
set-variable = long_query_time=20
set-variable = join_buffer_size=1M
set-variable = connect_timeout=20
set-variable = max_connect_errors=10
set-variable = max_connections=500
set-variable = key_buffer=128M
set-variable = max_allowed_packet=4M
set-variable = table_cache=1024
set-variable = sort_buffer=4M
set-variable = record_buffer=1M
set-variable = myisam_sort_buffer_size=64M
set-variable = thread_cache=256
skip-innodb
skip-bdb
#log-bin

以上都针对MyISAM
另外 php 连接 mysql 的 persistent connect 会造成有大量到 mysqld 的空闲连接
因为每启动一个连接都要时间和资源,而空闲连接过多则会导致当机,这样就要取消
pconnect 来维持系统稳定,当然性能会降低少许