📄 һЩ mysql
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html><head>
<title>KehuiCMS技术文档-: 一些 Mysql 的优化经验 -可慧网络 KehuiCMS 内容管理系统官方网站</title>
<meta name="keywords" content="编程技术,php,asp,cgi,perl,jsp,下载,源码,数据库,教程,免费服务,论坛,mysql,server,vb,javascript,oracle,css,hacker,黑客,linux,windows,freesoftware,download,forum,bbs,unix,database,programming">
<meta name="description" content="网站内容管理系统,web content management system,虚拟主机,hosting,免费服务,最全的编程资料库,论坛,专栏,column 和网页邮件功能">
<meta name="robots" content="all,follow">
<meta name="distribution" content="global">
<meta name="revisit-after" content="7 days">
<meta name="rating" content="general">
<meta name="copyright" content="2003 kehui.net">
<meta name="author" content="kehui.net">
<meta http-equiv=content-type content="text/html; charset=gb2312">
<link href="http://www.kehui.net/template/kehui/images/blocks.css" media="screen, projection" type="text/css" rel="stylesheet">
<script>
function smallwindow(link){
window.open(link,"newwindow","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,width=400, height=420,left=200,top=200");
}
</script>
<style>
.clr
</style>
</head>
<body>
<DIV id=pagewidth>
<table id=header border=0 cellspacing=0 cellpadding=0 align=center>
<tr><td class="topmenu" colspan=2>
<a href=http://www.kehui.net/index.php?op=main&file=passport title="申请个人通行证,登陆后可以在本站所有站点及模块中通行"><font color=#FFFFFF>申请通行证</font></a> | <a href=http://www.kehui.net/index.php?op=main&file=member&action=getpassword title="如果你忘记了密码,请使用此功能找回"><font color=#FFFFFF>密码找回</font></a> | <a href=http://www.kehui.net/index.php?op=main&file=member title="查看或修改个人资料"><font color=#FFFFFF>个人资料</font></a> | <a href=http://www.kehui.net/productreg.php title="注册KehuiCMS,注册后将由演示版自动升级为免费版"><font color=#FFFFFF>产品注册</font></a> | <a href=http://www.kehui.net/index.php?action=loginform title="使用通行证帐号登录,登录后可以通行全站"><font color=#FFFFFF>登录</font></a> | <a href=http://www.kehui.net/index.php?action=logout title="如果你不是在自己家里上网,在浏览完毕后退出登录可以保护你的资料"><font color=#FFFFFF>登出</font></a> |
</td></tr>
<tr class=logoarea>
<td>
<img src="http://www.kehui.net/template/kehui/images/logo.gif" alt="">
</td>
<td>
<div style="text-align:center;">
<script type="text/javascript"><!--
google_ad_client = "pub-1695435415603334";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_channel ="8353882618";
google_ad_type = "text_image";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</td>
</tr>
<tr><td class="menu" colspan=2>
<a href=http://www.kehui.net/index.php title="返回首页">首页</a> | <a href=http://www.kehui.net/index.php?op=article title="技术文档">文档</a> | <a href=http://www.kehui.net/index.php?op=download title="软件下载">下载</a> | <a href=http://www.kehui.net/index.php?op=column title="专栏文章">专栏</a> | <a href=http://www.kehui.net/index.php?op=libretto title="歌词库,收集大量国内外歌词,提供即时查询">歌词库</a> | <a href=http://www.kehui.net/index.php?op=law title="法律法规库,拥有大量法律法规条文,供即时查?><br><input type=">法规库</a> | <a href=http://www.kehui.net/index.php?op=WebMail&file=contactbook title="个人通讯录">通讯录</a> | <a href=http://www.kehui.net/index.php?op=bbs title="用户讨论区">论坛</a> | <a href=http://www.kehui.net:9090 title="可慧网络聊天中心,使用Kehui Socket Server Push聊天室,可容纳大量用户同时聊天">聊天</a> | <a href=http://www.kehui.net/index.php?op=faq title="提供系统及用户使用中的常见问题,大多数使用中所遇到的问题可以在这里找到答案">常见问题</a> | <a href=# onclick='smallwindow("privmsg.php?job=receivebox")' title="收发个人短信">短信</a> | <a href=http://www.kehui.net/link/khlink.exe title="加入可慧网络网站链接">链接</a> | <a href=http://www.kehui.net/index.php?op=news title="站内新闻,提供站点内部事件的最新消息">站内新闻</a> | <a href=http://www.kehui.net/index.php/column/index/15 title="文学书库拥有大量书籍,所有小说,文档,帖子都可以生成电子书下载回去放到PDA中阅读">文学书库</a> |
</td></tr>
</table>
<div class="clr"></div>
<div id=ads>
<div class=adscontent>
<iframe marginwidth=0 marginheight=0 frameborder=0 bordercolor='#000000' scrolling=no src='http://adsence.sogou.com/index.html?pid=kehui&ww=120&dc=1&dir=0&num=6&color=1' width=767 height=60></iframe>
</div></div>
<div class="clr"></div>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr>
<td valign=top class=left>
</td> <td valign=top width=100% class=center>
<table width=98% border=0><tr><td id=userinfo align=left></td><td id=newmessagesnum align=right></td></tr></table>
<div class="clr"></div>
<div id=location>
当前位置:<a href=http://www.kehui.net/index.php>首页</a>→<a href=http://www.kehui.net/index.php/article>技术文档</a>→<a href=http://www.kehui.net/index.php/article/index/39>Mysql</a>→ 一些 Mysql 的优化经验 <a href="http://www.kehui.net/index.php?op=article&file=pdb&aid=41280"><img src=http://www.kehui.net/template/kehui/images/saveas.gif border=0>下载至pda[电子书自动生成]</a>
</div>
<div id="read">
<div id="readtitle">一些 Mysql 的优化经验 </div>
<div id="readpostby">文章发表:sino_reason 发表日期:2005-04-03 阅读次数:0</div>
<div id="readcontent">
<script type="text/javascript"><!--
google_ad_client = "pub-1695435415603334";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "B0E0E6";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "336699";
google_color_text = "333333";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><OL>
<LI>从数据库结构做起
<OL>
<LI>字段类型的定义时遵循以下规则:
<OL>
<LI>选用字段长度最小
<LI>优先使用定长型
<LI>尽可能的定义 "NOT NULL"
<LI>数值型字段中避免使用 "ZEROFILL"
<LI>如果要储存的数据为字符串, 且可能值已知且有限, 优先使用 enum 或 set</LI></OL>
<LI>索引的优化至关重要(以下如果没有特殊说明, 均指查询密集的情况)
<OL>
<LI>被索引的字段的长度越小, 该索引的效率越高
<LI>被索引的字段中, 值的重复越少, 该索引的效率越高
<LI>查询语句中, 如果使用了 "group" 子句, 根据其中字段出现的先后顺序建立多字段索引
<LI>查询语句中, 如果使用了 "distinct", 根据其中字段出现的先后顺序建立多字段索引
<LI>"where" 子句中, 出现对同一表中多个不同字段的 "and" 条件时, 按照字段出现的先后顺序建立多字段索引
<LI>"where" 子句中, 出现对同一表中多个不同字段的 "or" 条件时, 对重复值最少的字段建立单字段索引
<LI>进行 "内/外连接" 查询时, 对 "连接字段" 建立索引
<LI>对 "主键" 的 "unique" 索引 毫无意义, 不要使用
<LI>被索引字段尽可能的使用 "NOT NULL" 属性
<LI>对写入密集型表, 尽量减少索引, 尤其是 "多字段索引" 和 "unique" 索引</LI></OL></LI></OL>
<LI>查询语句的优化
<OL>
<LI>多多利用 "explain" 查询索引使用情况, 以便找出最佳的查询语句写法和索引设置方案
<LI>慎用 "select *", 查询时只选出必须字段
<LI>查询使用索引时, 所遍历的索引条数越少, 索引字段长度越小, 查询效率越高 (可使用 "explain" 查询索引使用情况)
<LI>避免使用 mysql 函数对查询结果进行处理, 将这些处理交给客户端程序负责
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -