文章目录
很多也是,了解就行
数据库时间戳问题
(基于自己做过的项目)
结论: 用时间戳做筛选计算和筛选,date 相关只用来做展示。时间戳是金标准(UTC),不过如果是固定的日期字符串,在不同地点会转换为不同的时间戳。
时间戳(timeMiilli)只要有转换的函数就是统一的
时间戳 13 位是 ms,10 位是 s
用 time.TIme 或者 date 类型,会有各种错误
取 date,避免 gorm 的调用,可以用 string 类型,这样日期不会被 ORM 如gorm 调用修改,直接和数据库中的比对
createtime 和 updatetime 可以不传入,靠数据库自己更新就行
关键在于:
检查前端传递的 unix,数据库中存储的 unix,再定自己的 unxi 是 loc 还是 UTC(再限制一天开始到结束)
再存到数据库中
string 也可以存储 go 中 json
登录 mysql
bash
mysql -u username -p password -h host -P port
本地账号:

修改方式: https://blog.csdn.net/Aimee1717/article/details/129447994
增
sql
INSERT employee (name,gender,birthday,salary,department) VALUES ("yuan",1,"1985-12-12",8000,"教学部"), ("alvin",1,"1987-08-08",5000,"保安部");
删
结合语句筛选删除
sql
delete from author where name = 'bob'
## 改
```sql
ALter: change the property of a column
UPDATE employee SET salary = salary + 1000 , dep = 'Management';(where xx = xx)
update emp set salary=20000 where age > 30;
查
selcet
标准格式
sql
SELECT *|field1, field2 ...
FROM tab_name
WHERE 条件
GROUP BY field
HAVING 筛选
ORDER BY field
LIMIT 限制条数;
一对多(一个出版社对应多本书),谁是多在哪设置外键
多对多
设置中间过渡表
leftjoin/rightjoin
谁
笛卡尔积查询
select * from author,authordetail; -> 全部都会两两组合然后呈现
检查数据库时间
sql
SHOW VARIABLES LIKE '%time_zone%';
SELECT NOW()