mysql 基本操作

2021-05-13  本文已影响0人  逍遥_yjz

Python中创建GUID / UUID,序列号

>>> import uuid
>>> uuid.uuid4()
UUID('bd65600d-8669-4903-8a14-af88203add38')
>>> str(uuid.uuid4())
'f50ec0b7-f960-400d-91f0-c42a6d44e3d0'
>>> uuid.uuid4().hex
'9fe2c4e93f654fdbb24c02b15259716c'

1. 建表

CREATE TABLE IF NOT EXISTS `waterLevel`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `baseline_time` datatime,
   `pre_level` VARCHAR(40) NOT NULL,
   PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `tips`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `total_bill` int,
   `tip` int,
   `sex` VARCHAR(40) NOT NULL,
   `smoker` VARCHAR(40) NOT NULL,
   `day` VARCHAR(40) NOT NULL,
   `time` VARCHAR(40) NOT NULL,
   `size` VARCHAR(40) NOT NULL,
   PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. 插入数据

INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES("学习 PHP", "菜鸟教程", NOW());

INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES ("学习 MySQL", "菜鸟教程", NOW());

INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES ("JAVA 教程", "RUNOOB.COM", '2016-05-06');

3.sql语句清空表数据

数据表的清空有三种方式:

1.delete------ 是逐行删除速度极慢,不适合大量数据删除。

Delete from tablename where 1=1

2.truncate---- 删除所有数据,保留表结构,不能撤消还原。

TRUNCATE TABLE tablename

3.drop-------- 删除表,数据和表结构一起删除,快速。

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for docker2
-- ----------------------------
DROP TABLE IF EXISTS `docker2`;
CREATE TABLE `docker2` (
  `name` varchar(255) NOT NULL,
  `path` varchar(500) DEFAULT NULL,
  `docker1_name` varchar(255) NOT NULL,
  `tag1` varchar(255) DEFAULT NULL,
  `tag2` varchar(255) DEFAULT NULL,
  `tag3` varchar(255) DEFAULT NULL,
  `tag4` varchar(255) DEFAULT NULL,
  `tag5` varchar(255) DEFAULT NULL,
  `tag6` varchar(255) DEFAULT NULL,
  `tag7` varchar(255) DEFAULT NULL,
  `tag8` varchar(255) DEFAULT NULL,
  `tag9` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`docker1_name`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

4.时间查询

select * from DWD_D_FORECAST where to_char(TM1,'YYYY-MM-DD HH24:MI:SS')  = '2021-05-24 23:30:00'

5. 查询表的结构

fields = cursor.description
print(fields)

6. 表及其数据复制到另一个表

https://bbs.csdn.net/topics/290046277
https://zhidao.baidu.com/question/160923684.html

上一篇下一篇

猜你喜欢

热点阅读