mysql表优化、分析、检查和修复的方法详解_MySQL
本文实例讲述了mysql表优化、分析、检查和修复的方法。分享给大家供大家参考,具体如下:
这里介绍对数据库的管理常规就是进行预防性的维护,以及修复那些出现问题的内容。
进行检查和修复通常具有四个主要的任务:
1. 对表进行优化
2. 对表进行分析(分析并存储MyISAM和BDB表中键的分布)
3. 对表进行检查(检查表的错误,并且为MyISAM更新键的统计内容)
4. 对表进行修复(修复被破坏的MyISAM表)
一、对表进行优化
优化表有很多方式实现: OPTIMIZE TABLE语句、mysqlcheck工具(服务器要运行)或myisamchk(服务器没有运行或表中没有交互)
为什么优化?随着MySQL的使用,包括BLOB和VARCHAR字节的表将变得比较繁冗,因为这些字段长度不同,对记录进行插入、更新或删除时,会占有不同大小的空间,记录就会变成碎片,且留下空闲的空间。像具有碎片的磁盘,会降低性能,需要整理,因此要优化。
1. 利用OPTIMIZE语句对表进行优化
# mysql>OPTIMIZE TABLE 表名
这样就对表名进行了优化。
2. 利用mysqlcheck对表进行优化
mysqlcheck可进行优化外,还可执行大量的检查和修复任务。
# mysqlcheck -o 数据库名 表名 -uroot -p111111 (一张表) # mysqlcheck -o 数据库名 表名1 表名2 -uroot -p111111 (多张表) # mysqlcheck -o 数据库名 -uroot -p111111 (对整个数据库)
3. 利用myisamchk对表进行优化
# myisamchk --quick --check-only-changed --sort-index --analyze 表名 # myisamchk -r 表名 (参数-r表示对表进行修复,同时也删去了浪费的空间) # myisamchk -r /usr/local/mysql/data/testblog/article (指定表所在的路径)
以上操作需在服务器关闭或没有与服务器互操作的时候,可以使用myisamchk命令行工具(如果服务器正在运行,那么在运行这条语句之前利用mysqladmin flush-tables对表进行刷新。需确保服务器没有与表进行互操作,否则会出现故障)。myisamchk是最老的方法。必须在正确位置上运行myisamchk,或者指定表所在的路径。
注意:在优化过程中,表会被锁住,因此不要在忙时进行优化操作。同样,需要有足够的空间才能进行OPTIMIZE TABLE。如果没有磁盘空间,MySQL将不能进行优化,表也无法使用。
优化是对包含MyISAM表的数据库的常规管理事务中一个重要环节,应该定期进行。
二、对表进行分析
对表的定期分析可以改善性能,且应该成为常规维护工作的一部分。因为通过更新表的索引信息对表进行分析,可改善数据库性能。
有三种方法可以对表进行分析:
1. 连接到MySQL时,使用ANALYZE TABLE语句
2. 利用mysqlcheck命令行工具(服务器需要运行,并且只对MyISAM表起作用)
3. 利用myisamchk命令行工具(服务器不应该运行,或无对所操作的表发生互操作)
# ANALYZE TABLE 表名; # mysqlcheck -a 数据库名 表名 -uroot -p111111 # mysqlcheck -a 数据库名 表名1 表名2 -uroot -p111111
如果试图对不支持分析操作的表进行分析(如InnoDB),那操作将无法进行
# myisamchk -a /usr/local/mysql/data/数据库/表名
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》、《MySQL数据库锁相关技巧汇总》及《MySQL常用函数大汇总》
希望本文所述对大家MySQL数据库计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

A Comprehensive Guide to PHP 500 Errors: Causes, Diagnosis, and Fixes During PHP development, we often encounter errors with HTTP status code 500. This error is usually called "500InternalServerError", which means that some unknown errors occurred while processing the request on the server side. In this article, we will explore the common causes of PHP500 errors, how to diagnose them, and how to fix them, and provide specific code examples for reference. Common causes of 1.500 errors 1.

1. Press win+r to open the run window, enter [regedit] and press Enter to open the registry editor. 2. In the opened registry editor, click to expand [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun]. In the blank space on the right, right-click and select [New - String Value], and rename it to [systray.exe]. 3. Double-click to open systray.exe, modify its numerical data to [C:WindowsSystem32systray.exe], and click [OK] to save the settings.

Airplane mode is very convenient in some situations. However, the same airplane mode may give you a headache if your iPhone suddenly gets stuck on it. In this article, we have designed this set of solutions to get your iPhone out of airplane mode. Quick fix – 1. Try disabling Airplane Mode directly from Control Center. 2. If you are unable to disable Airplane Mode from Control Center, you can disable Airplane Mode directly from the Settings tab – If these tips don’t work, follow the fixes below to resolve the issue. Fix 1 – Force Restart Your Device The process of force restarting your device is very simple. All you have to do is follow these step-by-step instructions. Step 1 – You can start the process by pressing and releasing the Volume Up button. step

Time complexity measures the execution time of an algorithm relative to the size of the input. Tips for reducing the time complexity of C++ programs include: choosing appropriate containers (such as vector, list) to optimize data storage and management. Utilize efficient algorithms such as quick sort to reduce computation time. Eliminate multiple operations to reduce double counting. Use conditional branches to avoid unnecessary calculations. Optimize linear search by using faster algorithms such as binary search.

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

1. Press the key combination (win key + R) on the desktop to open the run window, then enter [regedit] and press Enter to confirm. 2. After opening the Registry Editor, we click to expand [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorer], and then see if there is a Serialize item in the directory. If not, we can right-click Explorer, create a new item, and name it Serialize. 3. Then click Serialize, then right-click the blank space in the right pane, create a new DWORD (32) bit value, and name it Star

Title: Is Tencent’s main programming language Go: An in-depth analysis. As China’s leading technology company, Tencent has always attracted much attention in its choice of programming languages. In recent years, some people believe that Tencent mainly adopts Go as its main programming language. This article will conduct an in-depth analysis of whether Tencent's main programming language is Go, and give specific code examples to support this view. 1. Application of Go language in Tencent Go is an open source programming language developed by Google. Its efficiency, concurrency and simplicity are loved by many developers.
