limited time offer

What is an index? How can an index be declared in MySQL?

An index is a data structure of a MySQL table that is used to speed up the queries.

It is used by the database search engine to find out the records faster. One or more fields of a table can be used as an index key. Index key can be assigned at the time of table declaration or can be assigned after creating the table.

To create index use below command:

CREATE TABLE users(
username VARCHAR(50) PRIMARY KEY,
email VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
INDEX (username, email));

To show index use below command:

mysql> SHOW INDEXES FROM Shopping.users;