mysql 300万数据查询500多秒如何优化

WBOY
풀어 주다: 2016-06-13 12:36:52
원래의
925명이 탐색했습니다.

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 如下:
<br />
<br />
mysql> explain SELECT id,pid,keyWords,shortUrl FROM  keywords  WHERE pid=0 ORDER BY id DESC LIMIT 50;<br />
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+<br />
| id | select_type | table    | type | possible_keys | key  | key_len | ref   | rows    | Extra                       |<br />
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+<br />
|  1 | SIMPLE      | keywords | ref  | pid           | pid  | 4       | const | 2452523 | Using where; Using filesort |<br />
+----+-------------+----------+------+---------------+------+---------+-------+---------+-----------------------------+<br />
1 row in set (8.18 sec)<br />
<br />
로그인 후 복사


另外mysql cpu占用很高怎么回事?内存:512M

配置文件如下:

<br>
# Example MySQL config file for small systems.<br>
#<br>
# This is for a system with little memory (
# from time to time and it's important that the mysqld daemon<br>
# doesn't use much resources.<br>
#<br>
# You can copy this file to<br>
# /etc/my.cnf to set global options,<br>
# mysql-data-dir/my.cnf to set server-specific options (in this<br>
# installation this directory is /usr/local/mysql/var) or<br>
# ~/.my.cnf to set user-specific options.<br>
#<br>
# In this file, you can use all long options that a program supports.<br>
# If you want to know which options a program supports, run the program<br>
# with the "--help" option.<br>
<br>
# The following options will be passed to all MySQL clients<br>
[client]<br>
#password	= your_password<br>
port		= 3306<br>
socket		= /tmp/mysql.sock<br>
<br>
# Here follows entries for some specific programs<br>
<br>
# The MySQL server<br>
[mysqld]<br>
port		= 3306<br>
socket		= /tmp/mysql.sock<br>
skip-locking<br>
key_buffer = 16K<br>
max_allowed_packet = 1M<br>
table_cache = 4<br>
sort_buffer_size = 64K<br>
read_buffer_size = 256K<br>
read_rnd_buffer_size = 256K<br>
net_buffer_length = 2K<br>
thread_stack = 64K<br>
datadir=/www/mysql/data<br>
log-slow-queries=/www/log/mysql/slowquery.log<br>
long_query_time=2<br>
<br>
<br>
# Don't listen on a TCP/IP port at all. This can be a security enhancement,<br>
# if all processes that need to connect to mysqld run on the same host.<br>
# All interaction with mysqld must be made via Unix sockets or named pipes.<br>
# Note that using this option without enabling named pipes on Windows<br>
# (using the "enable-named-pipe" option) will render mysqld useless!<br>
# <br>
#skip-networking<br>
server-id	= 1<br>
<br>
# Uncomment the following if you want to log updates<br>
#log-bin=mysql-bin<br>
<br>
# Uncomment the following if you are NOT using BDB tables<br>
#skip-bdb<br>
<br>
# Uncomment the following if you are using InnoDB tables<br>
#innodb_data_home_dir = /usr/local/mysql/var/<br>
#innodb_data_file_path = ibdata1:10M:autoextend<br>
#innodb_log_group_home_dir = /usr/local/mysql/var/<br>
#innodb_log_arch_dir = /usr/local/mysql/var/<br>
# You can set .._buffer_pool_size up to 50 - 80 %<br>
# of RAM but beware of setting memory usage too high<br>
#innodb_buffer_pool_size = 16M<br>
#innodb_additional_mem_pool_size = 2M<br>
# Set .._log_file_size to 25 % of buffer pool size<br>
#innodb_log_file_size = 5M<br>
#innodb_log_buffer_size = 8M<br>
#innodb_flush_log_at_trx_commit = 1<br>
#innodb_lock_wait_timeout = 50<br>
<br>
[mysqldump]<br>
quick<br>
max_allowed_packet = 16M<br>
<br>
[mysql]<br>
no-auto-rehash <div class="clear">
                 
              
              
        
            </div>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!