Hareware
1. put data in more than one hard disc, it can accelerate access data especially the size of data is very huge
2. enlarge
bandwidth and capacity of main memory
3. one server do one job
Software
First of all, we need know which querys cost a lot of time, there are some ways to find out:
Use SHOW STATUS to know the fequency of each opration mysql use, it's very useful when we want to why mysql use a lot of time
the word in the list:Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量。Aborted_connects 尝试已经失败的MySQL服务器的连接的次数。Connections 试图连接MySQL服务器的次数。Created_tmp_tables 当执行语句时,已经被创造了的隐含临时表的数量。Delayed_insert_threads 正在使用的延迟插入处理器线程的数量。Delayed_writes 用INSERT DELAYED写入的行数。Delayed_errors 用INSERT DELAYED写入的发生某些错误(可能重复键值)的行数。Flush_commands 执行FLUSH命令的次数。Handler_delete 请求从一张表中删除行的次数。Handler_read_first 请求读入表中第一行的次数。Handler_read_key 请求数字基于键读行。Handler_read_next 请求读入基于一个键的一行的次数。Handler_read_rnd 请求读入基于一个固定位置的一行的次数。Handler_update 请求更新表中一行的次数。Handler_write 请求向表中插入一行的次数。Key_blocks_used 用于关键字缓存的块的数量。Key_read_requests 请求从缓存读入一个键值的次数。Key_reads 从磁盘物理读入一个键值的次数。Key_write_requests 请求将一个关键字块写入缓存次数。Key_writes 将一个键值块物理写入磁盘的次数。Max_used_connections 同时使用的连接的最大数目。Not_flushed_key_blocks 在键缓存中已经改变但是还没被清空到磁盘上的键块。Not_flushed_delayed_rows 在INSERT DELAY队列中等待写入的行的数量。Open_tables 打开表的数量。Open_files 打开文件的数量。Open_streams 打开流的数量(主要用于日志记载)Opened_tables 已经打开的表的数量。Questions 发往服务器的查询的数量。Slow_queries 要花超过long_query_time时间的查询数量。Threads_connected 当前打开的连接的数量。Threads_running 不在睡眠的线程数量。Uptime 服务器工作了多少秒。关于上面的一些注释:如果Opened_tables太大,那么你的table_cache变量可能太小。如果key_reads太大,那么你的key_cache可能太小。缓存命中率可以用key_reads/key_read_requests计算。如果Handler_read_rnd太大,那么你很可能有大量的查询需要MySQL扫描整个表或你有没正确使用键值的联结(join)。
optimize select sentence and other query, such as use
LOAD DATA INFILE instead of
insert, it's faster
make grant easy, the cost will be less
check the lower layer interface of mysql if we really need high access speed, it's 2-5 times faster than sql sentence
Modify the configuration file
make grant easy, the cost will be less
check the lower layer interface of mysql if we really need high access speed, it's 2-5 times faster than sql sentence
Modify the configuration file
1.modify the
max_connections from 100(default) to a larger number, but it takes more main memory too, so choose a right number.
2.add
skip-name-resolve under
[mysqld] which can speedup query opration by deactive DNS serveice,it will make client connect to server faster. on the other side, we can't use computer name instead of ip address in grant table.
3.if we put mysql and web project in one server, add
skip-networking under
[mysqld] which can speedup query opration by deactive the networking.
4.add skip-locking under [mysqld] which can speedup query opration by unlock database, if we run multiple servers that use the same database directory (not recommended), each server must have external locking enabled, but it seems like that we don't run server like that
4.add skip-locking under [mysqld] which can speedup query opration by unlock database, if we run multiple servers that use the same database directory (not recommended), each server must have external locking enabled, but it seems like that we don't run server like that
5.add
log-slow-queries=/data/mysqldata/slowquery.log,
long_query_time=2, log-queries-not-using-indexes under the [mysqld] which can log the slow query and the query which does't use indexes.
6.add back_log = 384 under [mysqld] which means the number of request that were put into the stack before response, if we have a lot of concurrent request, maybe we need larger number, but we cann't use number which larger than number of system listen list(suggest number <= 512)
7.set key_buffer_size = 256M under [mysqld] , suggest using 256M or 384M when server use 4G main memory. Notice: server may run slower if we set too much buffer size.
8.set thread_concurrent = 4 under [mysqld], this parameter's value is 2 * logic CPU number of server
6.add back_log = 384 under [mysqld] which means the number of request that were put into the stack before response, if we have a lot of concurrent request, maybe we need larger number, but we cann't use number which larger than number of system listen list(suggest number <= 512)
7.set key_buffer_size = 256M under [mysqld] , suggest using 256M or 384M when server use 4G main memory. Notice: server may run slower if we set too much buffer size.
8.set thread_concurrent = 4 under [mysqld], this parameter's value is 2 * logic CPU number of server