Mysql导入.sql文件
- 进入数据库(要导入的数据库)
- 数据库中有要导入.sql文件名的数据库,没有则新建。
- source 路径+文件名
souce /home/robot/csql.sql
数据库文件.sql文件放在/home/robot目录下
按照时间删除数据库数据
DELETE FROM 表名 WHERE 时间段 >= 开始时间 AND 时间段 <= 结束时间
实例:
mysql> DELETE FROM EnvironmentRealData WHERE SmpDatetime >= '2019-07-01 00:00:00' AND SmpDatetime <= '2019-07-02 00:00:00'
-> ;
Query OK, 145 rows affected (0.01 sec)
mysql>
按照时间排序:
SELECT Rainfall FROM EnvironmentRealData ORDER BY SmpDatetime DESC;
SELECT SmpDatetime,Temprature,Humidity,WindSpeed,WindSpeed,WindDirection,Pressure,Rainfall FROM EnvironmentRealData ORDER BY SmpDatetime DESC
从一个表中插入另一个表的数据:
前提是:两张表的字段一致
实例:新建一张PointType表的Num字段想要继承devicespotrobotinfo表的Num信息:
INSERT INTO 目标表 (字段1,字段2,…) SELECT 字段 1,字段2,… FROM 来源表
进入数据库中:
INSERT INTO PointType(Num) SELECT Num from devicespotrobotinfo;
删除某列值为空的行:
delete from PointType where Num is null;
查看Num这列重复的:
SELECT Num,COUNT(*) FROM PointType GROUP BY Num HAVING COUNT(*) > 1;
删除表中重复的数据:
DELETE FROM PointType WHERE Num IN( SELECT Num FROM( SELECT Num,COUNT(*) FROM PointType GROUP BY Num HAVING COUNT(*) > 1 ) AS a ) LIMIT 1;