mysql 索引(index)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
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

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
存储 关系型数据库 MySQL
MySQL bit类型增加索引后查询结果不正确案例浅析
【8月更文挑战第17天】在MySQL中,`BIT`类型字段在添加索引后可能出现查询结果异常。表现为查询结果与预期不符,如返回错误记录或遗漏部分数据。原因包括索引使用不当、数据存储及比较问题,以及索引创建时未充分考虑`BIT`特性。解决方法涉及正确运用索引、理解`BIT`的存储和比较机制,以及合理创建索引以覆盖各种查询条件。通过`EXPLAIN`分析执行计划可帮助诊断和优化查询。
|
4天前
|
SQL 存储 关系型数据库
mysql加索引真的会锁表吗?揭秘背后的技术细节与规避策略
【8月更文挑战第16天】在数据库管理中,添加索引能大幅提升查询效率。MySQL执行此操作时的锁定行为常引起关注。文章详细解析MySQL中索引添加时的锁定机制及其原理。不同存储引擎及SQL语句影响锁定策略:MyISAM需全表锁定;InnoDB提供更灵活选项,如使用`ALTER TABLE... LOCK=NONE`可在加索引时允许读写访问,尽管可能延长索引构建时间。自MySQL 5.6起,在线DDL技术可进一步减少锁定时间,通过`ALGORITHM=INPLACE`和`LOCK=NONE`实现近乎无锁的表结构变更。合理配置这些选项有助于最小化对业务的影响并保持数据库高效运行。
14 4
|
4天前
|
SQL JavaScript 关系型数据库
Mysql索引不当引发死锁问题
本文通过真实案例解析了MySQL在高并发环境下出现死锁的问题。数据库表`t_award`包含多个索引,但在执行特定SQL语句时遭遇索引失效,导致更新操作变慢并引发死锁。分析发现,联合索引`(pool_id, identifier, status, is_redeemed)`因`identifier`允许为空值而导致索引部分失效。此外,`pool_id`上的普通索引产生的间隙锁在高并发下加剧了死锁风险。为解决此问题,文中提出了调整索引顺序至`(pool_id, status, is_redeemed, identifier)`等方案来优化索引使用,进而减轻死锁现象。
|
6天前
|
缓存 NoSQL Redis
一天五道Java面试题----第九天(简述MySQL中索引类型对数据库的性能的影响--------->缓存雪崩、缓存穿透、缓存击穿)
这篇文章是关于Java面试中可能会遇到的五个问题,包括MySQL索引类型及其对数据库性能的影响、Redis的RDB和AOF持久化机制、Redis的过期键删除策略、Redis的单线程模型为何高效,以及缓存雪崩、缓存穿透和缓存击穿的概念及其解决方案。
|
20天前
|
存储 SQL 关系型数据库
(六)MySQL索引原理篇:深入数据库底层揭开索引机制的神秘面纱!
《索引原理篇》它现在终于来了!但对于索引原理及底层实现,相信大家多多少少都有了解过,毕竟这也是面试过程中出现次数较为频繁的一个技术点。在本文中就来一窥`MySQL`索引底层的神秘面纱!
|
20天前
|
SQL 存储 关系型数据库
(五)MySQL索引应用篇:建立索引的正确姿势与使用索引的最佳指南!
在本篇中,则重点讲解索引应用相关的方式方法,例如各索引优劣分析、建立索引的原则、使用索引的指南以及索引失效与索引优化等内容。
|
24天前
|
SQL 缓存 关系型数据库
MySQL 查询索引失效及如何进行索引优化
MySQL 查询索引失效及如何进行索引优化
61 1
|
27天前
|
SQL 缓存 关系型数据库
面试题MySQL问题之实现覆盖索引如何解决
面试题MySQL问题之实现覆盖索引如何解决
30 1
|
14天前
|
缓存 关系型数据库 MySQL
MySQL调优秘籍曝光!从索引到事务,全方位解锁高可用秘诀,让你的数据库性能飞起来!
【8月更文挑战第6天】MySQL是顶级关系型数据库之一,其性能直接影响应用的高可用性与用户体验。本文聚焦MySQL的高性能调优,从索引设计到事务管理,逐一解析。介绍如何构建高效索引,如联合索引`CREATE INDEX idx_order_customer ON orders(order_id, customer_id);`,以及索引覆盖查询等技术。
39 0
|
20天前
|
存储 SQL 关系型数据库
(四)MySQL之索引初识篇:索引机制、索引分类、索引使用与管理综述
本篇中就对MySQL的索引机制有了全面认知,从索引的由来,到索引概述、索引管理、索引分类、唯一/全文/联合/空间索引的创建与使用等内容,进行了全面概述。