1、MySQL-Explain(不记得干嘛用的了,先存着)
参考链接:
MySQL-Explain详解_mysql explain-CSDN博客
2、shell脚本-项目sql升级
当项目需要从页面走升级或者回滚动作,sql得内置并执行shell
if [ $3 == "import" ];then
mkdir /root/work/$2/
unzip -o $1 -d /root/work/$2/
elif [ $3 == "action" ];then
/usr/bin/mysql -h localhost -uroot -p123456 < /root/work/$2/sql/upgrade.sql
fi
exit 0
参考链接:
通过shell实现数据库结构升级脚本_数据库升级脚本-CSDN博客
3、gorm使用
参考链接:
GORM基本操作 | 我的技术分享 (lsdcloud.com)
GORM - The fantastic ORM library for Golang, aims to be developer friendly.
4、mysql一些操作
删除唯一索引:
方法一:alter table 表名 drop index 索引名;
方法二:drop index 索引名 on 表名;
参考链接:
5、mysql自定义函数
项目中使用到函数,创建语句
-- mysql function
drop FUNCTION if exists getTimePoint;
DELIMITER //
CREATE
DEFINER=`root`@`%` FUNCTION `getTimePoint`(time datetime, startTime datetime, gap int) RETURNS datetime
NO SQL
BEGIN
RETURN from_unixtime(UNIX_TIMESTAMP(startTime) + ((UNIX_TIMESTAMP(time) - UNIX_TIMESTAMP(startTime)) div gap) * gap);
END
//
语法如下:
CREATE FUNCTION function_name(parameter_nametype,[parameter_name type,...])
RETURNS {STRING|INTEGER|REAL}
runtime_body
--复合结构的函数体的自定义函数--
DELIMITER //
CREATE FUNCTION function_name(parameter_nametype,[parameter_name type,...])
RETURNS {STRING|INTEGER|REAL}
BEGIN
//body
END
// /* 此处的”//“为告诉系统函数定义结束 */
参考链接: