×

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 Prefix index

Prefix index This index query creates an index column in the string or character column. MySQL system can create multiple indexes in the table. It will create in a table as...

3 minutes read.

MySQL LIKE() function

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

4 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Index

An index is a widely used method to access table information quickly. MySQL requires an index for operating table data stored in rows and columns. It's an entry point of...

3 minutes read.

MySQL Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL DATEDIFF() function

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

3 minutes read.

MySQL Environmental Setup

The MySQL Environmental Setup MySQL is free, open-source, and cross-platform software, which can be downloaded from its official website. MySQL management system installs on Linux, macOS, and windows. MySQL requires a framework...

6 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 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 FROM_BASE64() function

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

2 minutes read.

MySQL DATE_ADD() function

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

3 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 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 LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples. Introduction of MySQL LN() function For evaluation of the natural logarithm of...

2 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 MOD() 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 Basically, in MySQL, the MOD() function is...

3 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.