Home Database Mysql Tutorial MYSQL管理之索引改造简析_MySQL

MYSQL管理之索引改造简析_MySQL

Jun 01, 2016 pm 01:42 PM
Influence server

bitsCN.com
作为MYSQL DBA需要定期的查看服务器的索引情况,尤其是当你到了一个新的环境,开始接手一些数据库的维护工作,需要对线上服务器的索引使用情况有所了解。如果索引设置不合理,会导致服务器的性能受到非常大的影响,尤其是当SQL语句又比较复杂(比如多表联合查询等),本来就来大致介绍一下线上数据库的索引改造,本文只是对个人的工作总结,如果大家有更好的索引改造方案,也请指点。
 这里提到的索引改造主要分成如下几个阶段:
 一、去除重复的索引    1. 为什么要去除重复的索引A. 多余的索引占用磁盘空间,会引起不必要的磁盘ioB. 多余的索引会导致数据库在进行索引选择的时候变慢,尤其是索引越多的时候越突出(主要是相关联的索引才会影响索引选择)C. 重复的索引会导致表的更新变慢
 2. 如何找出重复的索引这里给大家介绍一个好用的Maatkit工具,Maatkit工具安装完成以后就会有一个mk-duplicate-key-checker命令,这个命令就是检测数据库中存在的重复索引,并会自动生成删除重复索引的语句,非常方便。
下面介绍Maatkit工具的安装和mk-duplicate-key-checker命令的使用。
 Maatkit工具的安装:wget http://maatkit.googlecode.com/files/maatkit-7540.tar.gztar zxvf maatkit-7540.tar.gz cd maatkit-7540     perl Makefile.PL make installmk-duplicate-key-checker命令的使用:mk-duplicate-key-checker --databases=databasename --user=root --password=passwd这里只需要制定数据库名,用户名以及密码,如果还想知道其他的一些参数,可以使用命令mk-duplicate-key-checker –help查看。备注:提醒大家一下,在执行完删除重复索引的语句之后,还需要再用这个工具重新检测一下,因为删除重复之后还可能会出现新的重复索引,尤其是PHPCMS V9的数据库。
 二、去除不必要的索引何为不必要的索引:我的理解是有一些字段辨识度很低的,比如abolish字段只有0和1,就没有必要建立索引,因为使用索引和全表扫描的速度差不多甚至肯能使用索引扫描会更慢。如果实在要建立,就根据查询情况和其他的字段建立组合索引效果会更好。
 1. 为什么要去除不必要的索引这个理由和去除重复的索引差不多,这里就不详述了。
 2.如何找出不必要的索引可以通过information_schema的STATISTICS表找出类似的索引,然后再经过人工过滤,应该还有更好的办法,呵呵。比如如下查询,能查询出制定库的辨识度低的列索引:SELECT TABLE_NAME,INDEX_NAME,COLUMN_NAME,CARDINALITY FROM `information_schema`.`STATISTICS` WHERE TABLE_SCHEMA='databasename' AND CARDINALITY 三、添加必须的索引何为必须的索引:我的理解比较简单就是会影响到查询性能的索引就是必须的索引
 1.  为什么要添加必须的索引必须的索引会影响到数据库的查询性能,很简单又很充分的理由,呵呵!
 2.   如何找出必须的索引    关于这个问题,我认为是比较有技术含量的,我的步骤如下:A. 找出性能差或者没有使用到索引的SQL语句要找出性能差或者没有使用到索引的SQL语句,需要做一些设置,比如将long_query_time设置成0.2秒左右,这个根据自己的环境来定,打开log_queries_not_using_indexes参数,可以通过set global log_queries_not_using_indexes=on;命令打开。可以通过mysqldumpslow命令来对慢查询日志进行统计,比如按照执行时间长短来提取或者按照执行次数来提取或者查询记录数来提取。列举两个非常常用的组合:mysqldumpslow -s t -t 10 slow.log  #找出10条消耗时间最长的慢查询SQLmysqldumpslow -s c -t 10 slow.log  #找出10条执行次数最多的满查询SQB.  通过explain和profiling分析性能差和没有用到索引的sql,确定需要添加的索引(也可能需要改写对应的SQL,这个不在本文的讨论范围),关于explain和profiling的用法读者可以自己查看相关的文档,这里不赘述。   作者 飞鸿无痕 bitsCN.com

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error Mar 24, 2024 am 09:51 AM

When trying to open a disk image in VirtualBox, you may encounter an error indicating that the hard drive cannot be registered. This usually happens when the VM disk image file you are trying to open has the same UUID as another virtual disk image file. In this case, VirtualBox displays error code VBOX_E_OBJECT_NOT_FOUND(0x80bb0001). If you encounter this error, don’t worry, there are some solutions you can try. First, you can try using VirtualBox's command line tools to change the UUID of the disk image file, which will avoid conflicts. You can run the command `VBoxManageinternal

How to solve the problem that eMule search cannot connect to the server How to solve the problem that eMule search cannot connect to the server Jan 25, 2024 pm 02:45 PM

Solution: 1. Check the eMule settings to make sure you have entered the correct server address and port number; 2. Check the network connection, make sure the computer is connected to the Internet, and reset the router; 3. Check whether the server is online. If your settings are If there is no problem with the network connection, you need to check whether the server is online; 4. Update the eMule version, visit the eMule official website, and download the latest version of the eMule software; 5. Seek help.

How effective is receiving phone calls using airplane mode? How effective is receiving phone calls using airplane mode? Feb 20, 2024 am 10:07 AM

What happens when someone calls in airplane mode? Mobile phones have become one of the indispensable tools in people's lives. It is not only a communication tool, but also a collection of entertainment, learning, work and other functions. With the continuous upgrading and improvement of mobile phone functions, people are becoming more and more dependent on mobile phones. With the advent of airplane mode, people can use their phones more conveniently during flights. However, some people are worried about what impact other people's calls in airplane mode will have on the mobile phone or the user? This article will analyze and discuss from several aspects. first

Solution to the inability to connect to the RPC server and the inability to enter the desktop Solution to the inability to connect to the RPC server and the inability to enter the desktop Feb 18, 2024 am 10:34 AM

What should I do if the RPC server is unavailable and cannot be accessed on the desktop? In recent years, computers and the Internet have penetrated into every corner of our lives. As a technology for centralized computing and resource sharing, Remote Procedure Call (RPC) plays a vital role in network communication. However, sometimes we may encounter a situation where the RPC server is unavailable, resulting in the inability to enter the desktop. This article will describe some of the possible causes of this problem and provide solutions. First, we need to understand why the RPC server is unavailable. RPC server is a

Detailed explanation of CentOS installation fuse and CentOS installation server Detailed explanation of CentOS installation fuse and CentOS installation server Feb 13, 2024 pm 08:40 PM

As a LINUX user, we often need to install various software and servers on CentOS. This article will introduce in detail how to install fuse and set up a server on CentOS to help you complete the related operations smoothly. CentOS installation fuseFuse is a user space file system framework that allows unprivileged users to access and operate the file system through a customized file system. Installing fuse on CentOS is very simple, just follow the following steps: 1. Open the terminal and Log in as root user. 2. Use the following command to install the fuse package: ```yuminstallfuse3. Confirm the prompts during the installation process and enter `y` to continue. 4. Installation completed

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Best Practice Guide for Building IP Proxy Servers with PHP Best Practice Guide for Building IP Proxy Servers with PHP Mar 11, 2024 am 08:36 AM

In network data transmission, IP proxy servers play an important role, helping users hide their real IP addresses, protect privacy, and improve access speeds. In this article, we will introduce the best practice guide on how to build an IP proxy server with PHP and provide specific code examples. What is an IP proxy server? An IP proxy server is an intermediate server located between the user and the target server. It acts as a transfer station between the user and the target server, forwarding the user's requests and responses. By using an IP proxy server

What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline Mar 13, 2024 pm 04:40 PM

What should I do if I can’t enter the game when the epic server is offline? This problem must have been encountered by many friends. When this prompt appears, the genuine game cannot be started. This problem is usually caused by interference from the network and security software. So how should it be solved? The editor of this issue will explain I would like to share the solution with you, I hope today’s software tutorial can help you solve the problem. What to do if the epic server cannot enter the game when it is offline: 1. It may be interfered by security software. Close the game platform and security software and then restart. 2. The second is that the network fluctuates too much. Try restarting the router to see if it works. If the conditions are OK, you can try to use the 5g mobile network to operate. 3. Then there may be more

See all articles