mysql 索引(index)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: mysql 索引(index)

注意:


1、   不要过度索引


2、   索引条件列(where后面最频繁的条件列)


3、   尽量索引散列值,过于集中的值不要索引。


索引类型


1、普通索引(index):仅仅是加快查询速度


2、唯一索引(unique index):行上的值不能重复


3、主键索引(primary key):主键不能索引


主键索引必定是唯一的,唯一索引不一定是主键,


一张表上只能一个主键,可以有一个或者多个唯一索引。


4、   全文索引(fulltext index):在mysql 默认情况下对于中文作用不大。


查看 一张表上的索引


show index from 表名(/G可以横着显示)






索引不知道名称默认以索引的列名作索引


建立索引



alter table 表名add index/unique/fulltext [索引名](列名)


[索引名]可以不写 ,不写默认与列名相同。


alter table 表名add primary key (列名)


创建索引示例:




为 tel列 创建普通索引

全文停止字:

全文索引,不针对非常频繁的词,做索引。

针对汉语意义不大,因为因为英文单词可以依赖空格等标点来判断单词界限,进而对单词进行索引,而中文mysql无法识别单词界限。

以下表列出了默认的全文停止字 :

a's


able


about


above


according


accordingly


across


actually


after


afterwards


again


against


ain't


all


allow


allows


almost


alone


along


already


also


although


always


am


among


amongst


an


and


another


any


anybody


anyhow


anyone


anything


anyway


anyways


anywhere


apart


appear


appreciate


appropriate


are


aren't


around


as


aside


ask


asking


associated


at


available


away


awfully


be


became


because


become


becomes


becoming


been


before


beforehand


behind


being


believe


below


beside


besides


best


better


between


beyond


both


brief


but


by


c'mon


c's


came


can


can't


cannot


cant


cause


causes


certain


certainly


changes


clearly


co


com


come


comes


concerning


consequently


consider


considering


contain


containing


contains


corresponding


could


couldn't


course


currently


definitely


described


despite


did


didn't


different


do


does


doesn't


doing


don't


done


down


downwards


during


each


edu


eg


eight


either


else


elsewhere


enough


entirely


especially


et


etc


even


ever


every


everybody


everyone


everything


everywhere


ex


exactly


example


except


far


few


fifth


first


five


followed


following


follows


for


former


formerly


forth


four


from


further


furthermore


get


gets


getting


given


gives


go


goes


going


gone


got


gotten


greetings


had


hadn't


happens


hardly


has


hasn't


have


haven't


having


he


he's


hello


help


hence


her


here


here's


hereafter


hereby


herein


hereupon


hers


herself


hi


him


himself


his


hither


hopefully


how


howbeit


however


i'd


i'll


i'm


i've


ie


if


ignored


immediate


in


inasmuch


inc


indeed


indicate


indicated


indicates


inner


insofar


instead


into


inward


is


isn't


it


it'd


it'll


it's


its


itself


just


keep


keeps


kept


know


knows


known


last


lately


later


latter


latterly


least


less


lest


let


let's


like


liked


likely


little


look


looking


looks


ltd


mainly


many


may


maybe


me


mean


meanwhile


merely


might


more


moreover


most


mostly


much


must


my


myself


name


namely


nd


near


nearly


necessary


need


needs


neither


never


nevertheless


new


next


nine


no


nobody


non


none


noone


nor


normally


not


nothing


novel


now


nowhere


obviously


of


off


often


oh


ok


okay


old


on


once


one


ones


only


onto


or


other


others


otherwise


ought


our


ours


ourselves


out


outside


over


overall


own


particular


particularly


per


perhaps


placed


please


plus


possible


presumably


probably


provides


que


quite


qv


rather


rd


re


really


reasonably


regarding


regardless


regards


relatively


respectively


right


said


same


saw


say


saying


says


second


secondly


see


seeing


seem


seemed


seeming


seems


seen


self


selves


sensible


sent


serious


seriously


seven


several


shall


she


should


shouldn't


since


six


so


some


somebody


somehow


someone


something


sometime


sometimes


somewhat


somewhere


soon


sorry


specified


specify


specifying


still


sub


such


sup


sure


t's


take


taken


tell


tends


th


than


thank


thanks


thanx


that


that's


thats


the


their


theirs


them


themselves


then


thence


there


there's


thereafter


thereby


therefore


therein


theres


thereupon


these


they


they'd


they'll


they're


they've


think


third


this


thorough


thoroughly


those


though


three


through


throughout


thru


thus


to


together


too


took


toward


towards


tried


tries


truly


try


trying


twice


two


un


under


unfortunately


unless


unlikely


until


unto


up


upon


us


use


used


useful


uses


using


usually


value


various


very


via


viz


vs


want


wants


was


wasn't


way


we


we'd


we'll


we're


we've


welcome


well


went


were


weren't


what


what's


whatever


when


whence


whenever


where


where's


whereafter


whereas


whereby


wherein


whereupon


wherever


whether


which


while


whither


who


who's


whoever


whole


whom


whose


why


will


willing


wish


with


within


without


won't


wonder


would


would


wouldn't


yes


yet


you


you'd


you'll


you're


you've


your


yours


yourself


yourselves


zero




注意!!换服务器导入数据:


大数据量时,先把索引去掉,导入后,统一加上索引。


索引加快查询速度,降低增删改的速度。


额外:


show create table  表名


可以查看  创建表的语句

————————————————

版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/w605283073/article/details/46572555

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
23天前
|
SQL 关系型数据库 MySQL
深入解析MySQL的EXPLAIN:指标详解与索引优化
MySQL 中的 `EXPLAIN` 语句用于分析和优化 SQL 查询,帮助你了解查询优化器的执行计划。本文详细介绍了 `EXPLAIN` 输出的各项指标,如 `id`、`select_type`、`table`、`type`、`key` 等,并提供了如何利用这些指标优化索引结构和 SQL 语句的具体方法。通过实战案例,展示了如何通过创建合适索引和调整查询语句来提升查询性能。
121 9
|
6天前
|
SQL 存储 关系型数据库
MySQL秘籍之索引与查询优化实战指南
最左前缀原则。不冗余原则。最大选择性原则。所谓前缀索引,说白了就是对文本的前几个字符建立索引(具体是几个字符在建立索引时去指定),比如以产品名称的前 10 位来建索引,这样建立起来的索引更小,查询效率更快!
54 22
 MySQL秘籍之索引与查询优化实战指南
|
7天前
|
存储 关系型数据库 MySQL
MySQL中为什么要使用索引合并(Index Merge)?
通过这些内容的详细介绍和实际案例分析,希望能帮助您深入理解索引合并及其在MySQL中的
35 10
|
27天前
|
缓存 关系型数据库 MySQL
MySQL 索引优化以及慢查询优化
通过本文的介绍,希望您能够深入理解MySQL索引优化和慢查询优化的方法,并在实际应用中灵活运用这些技术,提升数据库的整体性能。
69 18
|
20天前
|
存储 Oracle 关系型数据库
索引在手,查询无忧:MySQL索引简介
MySQL 是一款广泛使用的关系型数据库管理系统,在2024年5月的DB-Engines排名中得分1084,仅次于Oracle。本文介绍MySQL索引的工作原理和类型,包括B+Tree、Hash、Full-text索引,以及主键、唯一、普通索引等,帮助开发者优化查询性能。索引类似于图书馆的分类系统,能快速定位数据行,极大提高检索效率。
50 8
|
26天前
|
缓存 关系型数据库 MySQL
MySQL 索引优化以及慢查询优化
通过本文的介绍,希望您能够深入理解MySQL索引优化和慢查询优化的方法,并在实际应用中灵活运用这些技术,提升数据库的整体性能。
38 7
|
25天前
|
缓存 关系型数据库 MySQL
MySQL 索引优化与慢查询优化:原理与实践
通过本文的介绍,希望您能够深入理解MySQL索引优化与慢查询优化的原理和实践方法,并在实际项目中灵活运用这些技术,提升数据库的整体性能。
70 5
|
29天前
|
存储 关系型数据库 MySQL
Mysql索引:深入理解InnoDb聚集索引与MyisAm非聚集索引
通过本文的介绍,希望您能深入理解InnoDB聚集索引与MyISAM非聚集索引的概念、结构和应用场景,从而在实际工作中灵活运用这些知识,优化数据库性能。
130 7
|
15天前
|
存储 关系型数据库 MySQL
【MYSQL】 ——索引(B树B+树)、设计栈
索引的特点,使用场景,操作,底层结构,B树B+树,MYSQL设计栈
|
2月前
|
关系型数据库 MySQL Java
MySQL索引优化与Java应用实践
【11月更文挑战第25天】在大数据量和高并发的业务场景下,MySQL数据库的索引优化是提升查询性能的关键。本文将深入探讨MySQL索引的多种类型、优化策略及其在Java应用中的实践,通过历史背景、业务场景、底层原理的介绍,并结合Java示例代码,帮助Java架构师更好地理解并应用这些技术。
62 2