Home > Database > Mysql Tutorial > body text

What is an index? How to create an index in MySQL

黄舟
Release: 2017-08-02 14:06:50
Original
3841 people have browsed it

Index is a very magical thing. I remember when I was learning data structure, I learned B-tree. At that time, I was confused and confused. No matter what the teacher said, it was difficult to understand, but his role is to listen. Understand, it is this data structure that can improve the efficiency of queries.

Just like a book, if you want to read what Chapter 6, Section 6 is about, what would you do? Most people will definitely look at the table of contents, find the page number corresponding to this section, and then turn to this One page. This is the table of contents index to help readers quickly find the chapters they want. In the database, we also have indexes, whose purpose is of course the same as turning a book, and can help us improve the efficiency of queries. The index is just like a directory, which reduces the computer workload. It is very practical for databases with many table records and can greatly improve the query speed. Otherwise, if there is no index, the computer will scan one by one, scanning all records every time, wasting a lot of CPU time.

We all know that for an unordered table and an ordered table, there are more choices for query methods for the ordered table. The efficiency of each query method is also different. In fact, indexing is created for the table. , that is, sorting the records in the table according to the index field.

The following will introduce to you how to use mysql to create an index.

1. Confirm that mysql is installed and the service is up.

What is an index? How to create an index in MySQL

2. There are several ways to connect to mysql, as shown below.

What is an index? How to create an index in MySQL

What is an index? How to create an index in MySQL

What is an index? How to create an index in MySQL

#3. Use the command to enter the corresponding database and display the tables in the database. As shown below, we set the index for t_user.

What is an index? How to create an index in MySQL

What is an index? How to create an index in MySQL

What is an index? How to create an index in MySQL

#4. Use the command to create an index.

What is an index? How to create an index in MySQL

5. Use the command to display the index. We can see two indexes. We can find that when creating the database, if the primary key is set, mysql will automatically index the primary key.

What is an index? How to create an index in MySQL

6. You can also use commands to create multiple indexes.

What is an index? How to create an index in MySQL

7. Display index.

1What is an index? How to create an index in MySQL

The above is the detailed content of What is an index? How to create an index in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template