日期:2014-05-17  浏览次数:20411 次

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 (<= 64M) where MySQL is only used
# 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
l