EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MySQL Tutorial MySQL REINDEX
Secondary Sidebar
MySQL Tutorial
  • Functions
    • MySQL Function
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL IFNULL()
    • MySQL TIMESTAMPDIFF()
    • MySQL COALESCE()
    • MySQL count()
    • MIN() in MySQL
    • MySQL Numeric
    • MySQL field()
    • MySQL FIND_IN_SET()
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL Concat
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL Asynchronous
    • MySQL innodb_buffer_pool_size
    • MySQL key_buffer_size
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL Union
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • MySQL Clustered Index
    • MySQL? InnoDB Cluster
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • MySQL Optimize Table
    • TRUNCATE TABLE MySQL
    • MySQL Table Dump
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL LOWERCASE
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL AFTER UPDATE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL? INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL? Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MySQL DROP TRIGGER
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL?User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL?Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL Cluster
    • MySQL Partitioning
    • MySQL Full Text Search
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Basic
    • MySQL floor
    • MySQL DESCRIBE table
    • MySQL encryption
    • Introduction to MySQL
    • Is SQL Server a Database?
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • MySQL Community Server
    • How To Install MySQL
    • MySQL Versions
    • MySQL OpenSource
    • MySQL GUI Tools
    • MySQL Grant
    • MySQL Error 1064
    • MySQL Drop Database
    • MySQL not equal
    • MySQL SELECT INTO Variable
    • MySQL Commands
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • MYSQL COMMIT
    • MySQL FORMAT
    • Timestamp to Date in MySQL
    • MySQL DATEDIFF
    • MySQL?Incremental Backup
    • MySQL JSON Data Type
    • MySQL ENUM
    • MySQL Default Port
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL Cheat Sheet
    • MySQL ORDER BY Random
    • MySQL ORDER BY DESC
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
    • MySQL WHERE IN Array
    • MySQL Fetch Array
    • MySQL ISNULL
    • MySQL Index Types
    • Mysql? Export Schema
    • Amazon RDS for MySQL
    • MySQL greatest
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Advanced
    • MySQL Formatter
    • MySQL TINYINT
    • MySQL Grant All Privileges
    • MySQL DROP TABLE
    • MySQL rename database
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL IF EXISTS
    • MySQL UUID
    • Views in MySQL
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL AES_Encrypt
    • MySQL Performance Tuning
    • MySQL Transaction
    • MySQL? sort_buffer_size
    • MySQL? Sync
    • MySQL? Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
    • MySQL Partitioning
    • MySQL InnoDB
    • MySQL Float vs Decimal
    • MySQL Union vs Union All
  • Interview Questions
    • MySQL Interview Questions

Related Courses

MS SQL Certification Courses

Oracle Certification Courses

PL/SQL Certification Courses

MySQL REINDEX

By Aanchal SharmaAanchal Sharma

MySQL-REINDEX

Introduction to MySQL REINDEX

MySQL REINDEX is also a data structure in a database table which is a significant part to have a good database maintenance method where it is responsible to reorganize and manage the indexes and restores the speedy retrieval. Since MySQL INDEX is also defined as a data structure that helps to optimize the database and progresses the speed of the MYSQL operations in a table. We use REINDEX in MySQL to rebuild indexes using one or multiple columns in a table database to have quick data access and make the performance better. MySQL REINDEX denotes the re-indexing process to rebuild the indexes on a database if the database is corrupted or needs repair to optimize the tables and fetch the rows using indexes properly using phpMyAdmin.

Syntax

Generally, we can apply MySQL REINDEX or INDEXES can be formed easily via phpMyAdmin in local server like WAMP, XAMPP or live server on cPanel. Most of the MySQL indexes procedure such as PRIMARY KEY, UNIQUE, INDEX, FULLTEXT& REINDEX are warehoused in B-trees.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

B-tree can be defined as a self-balancing data structure tree that stores data in a sorted manner and allows sequential access, searches, insertions, and deletions on the basis of logarithmic time. It is beneficial for file systems and databases that are engaged to read and write huge blocks of information.

Except some like:

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)
  • For spatial data, types indexes are stored in R-trees
  • MEMORY tables use hash indexes
  • InnoDB supports reversed lists for FULLTEXT types of indexes.

We use the following simple syntax to add MySQL INDEX in a table:

CREATE INDEX [Index_Name] ON [TableName] ([ColumnName of the TableName]);

Now, for any reason you encounter the corruption of an index on the table, then you need to simply re-build that index or all of the indexes present on the table or columns by using the below basic syntax of REINDEX INDEX or even REINDEX TABLE and REINDEX DATABASE to repair particular database indexes.

REINDEX INDEX [Index_Name];
REINDEX TABLE [TableName]; or,
REINDEX TABLE [TableName]([ColumnName of the TableName]);
REINDEX DATABASE [DatabaseName];

The given arguments are explained as below:

  • Index_Name is said to be the name of the index.
  • TableName is the name of a particular table.
  • ColumnName defines the column where the indexing is to be done in the table mentioned above.
  • DatabaseName denotes the name of database name where we need to apply REINDEX in MySQL.

Here, REINDEX recreates the specified indexes for a single index, table index, and database index.

How MySQL REINDEX works?

In MySQL, REINDEX does the following works:

  • It can help to relocate the indexing information very fast within a database or table.
  • Here, re-indexing or simply indexing in MySQL will create an inner catalog which is stored by the MySQL service.
  • It uses the catalog of table rows as it can indicate within a decimal of time using the least effort.
  • A REINDEX TABLE redefines a database structure which rearranges the values in a specific manner of one or group of columns.
  • It works first by sorting the data and then works to allot identification for every row in a table.
  • The indexes are put together on the top of the tables and perform executions such as SELECT, DELETE, and UPDATE SQL statements quicker to deploy when the size of data is huge. The REINDEX or INDEX in MySQL can also be termed as a table which comprises of records arrangement technique.
  • Indexes help to search for rows corresponding to a WHERE clause with particular column values very quickly so if the index is not working properly, then we must use the REINDEX command to operate and rebuild the indexes of table columns to continue the access of data.
  • Eliminates rows from concern if there is the choice between more than one indexes by selective method indexing and thus supports the re-indexing also.
  • Indexing and re-indexing also allow fetching rows from other tables when performing JOINS properly.

Examples to Implement MySQL REINDEX

For using MySQL REINDEX let us first create some indexes on tables and explain about them to know in brief the topic:

Initially, we have taken a table named Person in the database with fields Person_ID, Person_Name &Person_Address. It contains few records as follows:

Code:

SELECT * FROM Person

Output:

MySQL REINDEX - 1

Examples #1

Now, the following query will find the person whose location is Delhi in the address column using WHERE:

Code #1

SELECT Person_ID, Person_Name FROM Person WHERE Person_Address= ‘Delhi’;

Output:

MySQL REINDEX - 2

Code #2

If you want to view how MySQL performed this query internally, use EXPLAIN to the start of the previous query as follows:

EXPLAIN SELECT Person_ID, Person_Name FROM Person WHERE Person_Address = ‘Delhi’;

Output:

use EXPLAIN

Here, the server has to test the whole table containing 7 rows to execute the query.

Example #2

Let us now add an index for address column by the below statement:

Code #1

CREATE INDEX Person_Address ON Person(Person_Address);

Output:

MySQL REINDEX - 4

After running the query, again use EXPLAIN to view the result now.

Code #2

EXPLAIN SELECT Person_ID, Person_Name FROM Person WHERE Person_Address = ‘Delhi’;

Output:

use EXPLAIN

The result is clear, now only 3 rows are scanned using the index created and not the whole table which is indicated in the key column.

If you want to see the index, use SHOW query as follows:

Code #3

SHOW INDEXES FROM Person;

Output:

SHOW query

Now, suppose that we have any corrupted index or if you no longer get the valid data due to any practical reasons but may not be possible in theory like software viruses or failures of hardware then, MySQL REINDEX will be responsible for a recovery process to repair the tables or database and rebuild the indexes to maintain the performance and optimization and quick operations within the databases.

Example #3

We can use REORGANISE, REPAIR, OPTIMIZE TABLE statements to rebuild the corrupted table and associated indexes to reduce the memory space and increase the I/O efficiency.

Code #1

REINDEX TABLE ‘Person’;

OR,

OPTIMIZE TABLE ‘Person’;

Output:

MySQL REINDEX - 7

After MySQL REINDEX the indexes will be rebuilt and we can view that as output here:

Code #2

SHOW INDEXES FROM Person;

Output:

MySQL REINDEX

Conclusion

MYSQL REINDEX statement can drop all indexes on a group or recreates them from scratch, which might cause costly for groups that contain large data or a number of indexes. REINDEX is helpful when we need to recover from the corruption of an index in the database or when the description of an ordering structure is altered. Therefore, REINDEX supports to regain the performance and utility to faster access and smooth going operations in a MySQL database table.

Recommended Articles

This is a guide to MySQL REINDEX. Here we discuss an introduction to MySQL REINDEX with appropriate syntax and programming examples. You can also go through our other related articles to learn more –

  1. What is MySQL Schema
  2. MySQL Subquery
  3. MySQL MAX() Function
  4. MIN() in MySQL
Popular Course in this category
MySQL Training Program (12 Courses, 10 Projects)
  12 Online Courses |  10 Hands-on Projects |  92+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

MS SQL Training (16 Courses, 11+ Projects)4.9
Oracle Training (14 Courses, 8+ Projects)4.8
PL SQL Training (4 Courses, 2+ Projects)4.7
1 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more