×

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 NOW() function

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

2 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 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 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 Create index

An index creation helps to make a row of the table unique. The index operates and handles table data quickly. MySQL index requires NOT NULL column constraint. The index column...

2 minutes read.

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL PERIOD_ADD() function

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

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 SOUNDEX() function

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

3 minutes read.

MySQL vs SQL

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

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

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

2 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 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 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 LOAD_FILE() function

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

3 minutes read.