×

MySQL Full text index

Full text index

The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table column changes, then the full-text index updates or recreate. MySQL version 5.6 allows using a full-text index in the table. The full-text index is used to create a table, create an index, and alter table statements.

Syntax

The basic syntax of the full-text index shows below.

FULLTEXT (column1, column2, … column)

The syntax of the full-text index with the create table command shows below.

 CREATE TABLE table_name (Column1 data type NOT NULL PRIMARY KEY,
 Column2 data type NOT NULL,
 Column3 data type NOT NULL,
 FULLTEXT (column1,column2,..)) 

The syntax of a full-text index with create index command shows below.

 CREATE FULLTEXT INDEX iname
 ON table name
 (column1,column2,..)) 

The syntax of the full-text index with alter table command shows below.

 ALTER TABLE tname
 ADD INDEX (column1,column2, …); 

The syntax of drop full-text index with alter table command shows below.

ALTER TABLE tnameDROP INDEX iname;

Examples of the FULLTEXT Index

1) Example: The basic full-text index example shows below.

Execute the following query to know about the full-text index. Here, we use a single column for the full-text key.

 mysql> create table index_table(
 roll_number INT NOT NULL AUTO_INCREMENT,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 comment text NOT NULL,
 img blob NOT NULL,
 PRIMARY KEY (roll_number),
 FULLTEXT KEY (mark)); 

OUTPUT

Execute the below query to get the full-text index and its information.

mysql> show index from index_table;
MySQL: Full text index

2) Example: The multiple full-text index example shows below.

Execute the following query to know about the "FULLTEXT" index. Here, you use multiple columns for the FULLTEXT key.  It would be best if you created a new table with the multiple "FULLTEXT" indexes.

 mysql> create table index_table(
 roll_number INT NOT NULL AUTO_INCREMENT,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 comment text NOT NULL,
 img blob NOT NULL,
 PRIMARY KEY (roll_number),
 FULLTEXT KEY (name, mark, comment)); 

OUTPUT

Execute the below query to get the full-text index and its information.

mysql> show index from index_table;
MySQL: Full text index

The above table image displays the index and its type. For example, the BTREE index type is represented by the primary index. The mark, name, and comment index show the "FULLTEXT" index type.

3) Example: The full-text index with the existing table example shows below.

Execute the following query to know about the "FULLTEXT" index. Here, you use single columns tothe FULLTEXT index on the existing table. You can create either single or multiple indexes on the available table.

 mysql> CREATE FULLTEXT INDEX name
 ON index_table (mark); 

OUTPUT

Execute the below query to get the full-text index and its information.

mysql> show index from index_table;
MySQL: Full text index

The above table shows the mark and name column as a full-text index type.  Here the mark index is already available, and the name index is created into an existing table.

4) Example: The full-text index with the existing table example shows below.

Execute the following query to know about the "FULLTEXT" index with ALTER table command. Here, you use multiple columns tothe FULLTEXT index on the existing table.It allows us to create either single or multiple indexes on the available table.

mysql> ALTER table index_table
ADD FULLTEXT (name, mark, comment);

OUTPUT

Execute the below query to get the full-text index and its information.

mysql> show index from index_table;
MySQL: Full text index

The above image shows an index with a full-text index type. The name and mark columns assign multiple times with different key names. You either create a full-text index or add an index on an existing table.

5) Example: The drop full-text index with the existing table example shows below.

Execute the following query to know about delete the "FULLTEXT" index with the ALTER table command. Here, you will deletemultiple columns ofthe FULLTEXT index from the existing table.

 mysql> ALTER table index_table
 DROP index name; 

OUTPUT

Execute the below query to get the full-text index and its information.

mysql> show index from index_table;
MySQL: Full text index

The output images displayed the available index and its type. Here the name_2 index is deleted from the table.


Related Topics

MySQL FIND_IN_SET() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function MySQL provides a built-in string function called...

4 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.

MySQL GREATEST function

This statement displays the greatest values of the table. The GREATEST function returns a null value when the table contains a null value. The GREATEST function needs a minimum of...

2 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 minutes read.

MySQL Advance function

The advance function operates numerical values, string values, and data types.  The advance function converts, displays, and compares given values as per requirement. Here, you find out database, table, and...

4 minutes read.

MySQL LOCATE() function

In this context, we will learn how we can use the MySQL LOCATE() function with proper syntax and good examples. Introduction of MySQL LOCATE() function LOCATE() function in MySQL is used for...

3 minutes read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL LENGTH() Function

In this context, we will learn how we can use the MySQL LENGTH() function with proper syntax and good examples. Introduction of MySQL LENGTH() function This function in MySQL is used to...

2 minutes read.

MySQL function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 minutes read.

MySQL FIELD() function

In this context, we will learn how we can use the MySQL FIELD() function with proper syntax and good examples. Introduction of MySQL FIELD() function The index position of a mentioned value...

3 minutes read.

MySQL PERIOD_DIFF() function

In this context, we will learn how we can use the MySQL PERIOD_DIFF() function with proper syntax and good examples. Introduction of MySQL PERIOD_DIFF() function This function in MySQL is used to...

2 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL ROUND() function

In this context, we will learn how we can use the MySQL ROUND() function with proper syntax and good examples. Introduction of MySQL ROUND() function The ROUND() function in MySQL is used...

3 minutes read.

MySQL Truncate() Function

In this context, we will learn how we can use the MYSQL TRUNCATE function to truncate a number to a mentioned number of decimal places. Syntax of MySQL Truncate Function A number...

2 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.