MySQL creates new user authorization, creates table partitions

Create a new user with a password that never expires:

CREATE USER market668@`` IDENTIFIED BY 'market886' PASSWORD EXPIRE NEVER;

Authorize the user to query a certain table:

GRANT Select ON tourism.* TO market668@``;
GRANT Select ON TABLE tourism.cell TO market668@``;

illustrate:

In the database version 5.7.36, the original intention is to authorize users to only query the cell table, and have no permissions to other tables. Only using the second command is invalid, and the first command must be added. As a result, because of the existence of the first command, the user can query all tables under the database.

In database version 8 and above, the original intention is to authorize users to only query the cell table, which can be achieved only by using the next day command.

Therefore, in a low-version database, if you want to set query permissions for certain tables for users, you need to verify in many ways after setting.

Deauthorize:

REVOKE Select ON TABLE tourism.cell FROM market668@``;

The advantage of MySQL using partitions is that some classified data can be placed in a partition, which can reduce the amount of data checked by the server and speed up queries .

Add partitions when creating a table:

CREATE TABLE CRT(
    ID VARCHAR(32) NOT NULL,
    CELL_ID VARCHAR(15) NULL,
    YEAR INT(11) NOT NULL,
    MONTH INT(11) NOT NULL,
    DAY INT(11) NULL,
    TIME INT NULL,
    MINUTE INT(11) NOT NULL,
    QUANTITY INT(11) NULL,
    PRIMARY KEY(ID, YEAR, MONTH)
) PARTITION BY RANGE COLUMNS(YEAR, MONTH) PARTITIONS 2(
    PARTITION P202205 VALUES LESS THAN(2022, 6),
    PARTITION P202206 VALUES LESS THAN(2022, 7));

Adjust the partition after the table is built:

ALTER TABLE CRT
PARTITION BY RANGE COLUMNS (YEAR, MONTH) (
	PARTITION p202301 VALUES LESS THAN (2023, 2),
	PARTITION p202302 VALUES LESS THAN (2023, 3),
	PARTITION p202303 VALUES LESS THAN (2023, 4),
	PARTITION p202304 VALUES LESS THAN (2023, 5)	
);
ALTER TABLE CRT
	ADD PARTITION (PARTITION p202305 VALUES LESS THAN (2023, 6));

We all know that MySQL database partitioning is a physical database-related design technology, and DBAs and MySQL database-related personnel are quite familiar with it. Although there are many partitioning techniques, their main purpose is to reduce the total amount of data read and write in specific SQL operations to shorten the response time. 

For those data that have lost the meaning of preservation, usually by deleting the partitions related to those data, those data can be easily deleted. Conversely, in some cases, the process of adding new data can be easily implemented by adding a new partition specifically for those new data.

The data in the cleaned partition is empty, and the reserved partition is not deleted, just the data is cleaned:

ALTER TABLE CRT TRUNCATE PARTITION 202205;

Delete partition:

ALTER TABLE CRT DROP PARTITION 202205;

Guess you like

Origin blog.csdn.net/kzhzhang/article/details/124857941