Home > Backend Development > PHP Tutorial > mysql 300万数据查询500多秒如何优化

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

WBOY
Release: 2016-06-13 12:36:52
Original
973 people have browsed it

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 />
Copy after login


另外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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template