1、登录mysql并使用test数据库
# 登录mysql数据库
qiang@09230:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25374
Server version: 8.0.29-0ubuntu0.20.04.3 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
#使用test数据库
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
2、查询表test_table指定日期前的数据总数
mysql> select count(*) from test_table where time < '2022-05-29 10:00:00';
+----------+
| count(*) |
+----------+
| 110400 |
+----------+
1 row in set (0.52 sec)
3、删除表test_table指定索引time在指定日期前的数据
mysql> delete from test_table where time < '2022-05-29 10:00:00';
Query OK, 0 rows affected (0.25 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.47 sec)
mysql> quit
Bye
qiang@09230:~$
验证:
mysql> select count(*) from test_table where time < '2022-05-29 10:00:00';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.07 sec)