mysql permissions and indexes

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

mysql permissions and indexes

The highest user of mysql is root,

We can create a user in the database, the statement is CREATE USER username IDENTIFIED BY 'password', we can also execute the CREATE USER username statement to create a user, but this user does not have a password, you can set the password after logging in the user; delete the user statement For the DROP USER user; the statement to change the user name is RENAME USER old user name to new user name;

Modify the password statement to set password=password('password');

The statement for advanced users to modify the passwords of other users is SET PASSWORD FOR user=PASSWORD('password'); .

image

The operations for granting permissions are as follows:

View the user permission statement as show grants for user;

The statement to grant user permission is grant permission on  .  to user, the first number represents the database, and the second number represents the table to be granted permission;

The statement to revoke user privileges is REVOKE CREATE ON  .  FROM user; the statement to flush is FLUSH PRIVILEGES.

image

MySQL's index allows us to search for data in the database faster. When we are programming, we can design the columns involved in the query as indexes by using the column of the class condition.

The index has a common index. Setting the common index has no effect on the data of the column, but it optimizes the search speed of the data; the value in the column whose unique index is set as the unique index is unique, which also improves the search speed of the data. Optimization; the primary key index is set to the primary key column and the primary key index will be added automatically. A table can only have one primary key column, and this column does not allow null values. Generally, the primary key index is created at the same time when the table is built; the full-text index is mainly used for searching keywords in the text, not directly compared to the value in the index. The fulltext index is very different from other indexes, it is more like a search engine, rather than a simple where statement parameter matching. The fulltext index is used with the match against operation, rather than the general where statement plus like. It can be used in create table, alter table, and create index, but currently only char, varchar, and text columns can create full-text indexes. It is worth mentioning that when the amount of data is large, now put the data into a table without a global index, and then use the CREATE index to create a fulltext index, rather than creating a fulltext for a table and then writing the data. The speed is much faster; there is also a composite index, which can combine two columns as a condition to query together, and a single column as a condition query will not have the effect of an index.

The statement to create the index is CREATE index type [not written as ordinary index] INDEX index name ON table (column).

DROP INDEX statement for DROP INDEX index name ON table.

Disadvantages of indexing:

1. Although the index greatly improves the query speed, it will reduce the speed of updating the table, such as insert, update and delete on the table. Because when the table is updated, not only the data but also the index file must be saved.

2. Create an index file that will occupy disk space. In general, this problem is not serious, but if you create multiple composite indexes on a large table, the index file will grow quickly. Indexes are only one factor to improve efficiency. If you have tables with large amounts of data, you need to spend time researching the establishment of the best indexes or optimizing query statements.

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326315354&siteId=291194637