mysql 300万数据查询500多秒怎么优化啊
本帖最后由 dz215136304 于 2013-08-15 11:33:52 编辑 linux下 mysql 300万数据查询500多秒怎么优化啊,其中pid已经做索引,id是主键
select id,pid,keywords,shorturl from keywords where pid=0 order by id desc limit 50
explain 如下:
mysql> explain select id,pid,keywords,shorturl from keywords where pid=0 order by id desc limit 50;
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | extra |
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+
| 1 | simple | keywords | ref | pid | pid | 4 | const | 2452523 | using where; using filesort |
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+
1 row in set (8.18 sec)
另外mysql cpu占用很高怎么回事?内存:512m
配置文件如下:
# example mysql config file for small systems.
#
# this is for a system with little memory (# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# you can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/var) or
# ~/.my.cnf to set user-specific options.
#
# in this file, you can use all long options that a program supports.
# if you want to know which options a program supports, run the program
# with the --help option.
# the following options will be passed to all mysql clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# here follows entries for some specific programs
# the mysql server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 16k
max_allowed_packet = 1m
table_cache = 4
sort_buffer_size = 64k
read_buffer_size = 256k
read_rnd_buffer_size = 256k
net_buffer_length = 2k
thread_stack = 64k
datadir=/www/mysql/data
log-slow-queries=/www/log/mysql/slowquery.log
long_query_time=2
# don't listen on a tcp/ip port at all. this can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# all interaction with mysqld must be made via unix sockets or named pipes.
# note that using this option without enabling named pipes on windows
# (using the enable-named-pipe option) will render mysqld useless!
#
#skip-networking
server-id = 1
# uncomment the following if you want to log updates
#log-bin=mysql-bin
# uncomment the following if you are not using bdb tables
#skip-bdb
# uncomment the following if you are using innodb tables
#innodb_data_home_dir = /usr/local/mysql/var/
#innodb_data_file_path = ibdata1:10m:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/var/
#innodb_log_arch_dir = /usr/local/mysql/var/
# you can set .._buffer_pool_size up to 50 - 80 %
# of ram but beware of setting memory usage too high
#innodb_buffer_pool_size = 16m
#innodb_additional_mem_pool_size = 2m
# set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5m
#innodb_log_buffer_size = 8m
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16m
[mysql]
no-auto-rehash