Home > Database > Mysql Tutorial > mysql的大量数据操作技巧_MySQL

mysql的大量数据操作技巧_MySQL

WBOY
Release: 2016-05-31 08:46:33
Original
1475 people have browsed it

最近几天在公司导数据,主要涉及对mysql的操作,几天下来在boss的指正下算是有了一点小心得:

如ex_table表中有100万条数据,主要字段uid,username,password,email,logintime,主键uid,现需要将其中的uid取出做另外一个查询条件,如果直接选择会造成表锁死,内存溢出。如 $query=mysql_query(select * from ex_table)。

技巧一,limit分页

$query=mysql_query('select count(*) as cnt  from ex_table ' );$res=mysql_fetch_assoc($query);$cnt=$res['cnt'];$pagesize=1000;$num=ceil($cnt/$pagesize);$start=0;for($i=0;$i<br>技巧二,利用uid分页;效率要高很多<br><p></p><pre class="brush:php;toolbar:false">$query=mysql_query('select max(uid)as max,min(uid) as min  from ex_table ' );$res=mysql_fetch_assoc($query);$max=$res['max'];$min=$res['min'];$pagesize=1000;for($i=$min;$i='{$i}'";   $start+=$pagesize;}
Copy after login

另外还有两个分析sql性能的关键字 explain desc,具体能显示哪些性能还不是太了解。

desc/explain select from ex_table where ````

就这么多了。

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