Mysql 中文排序,慢查询,UUID等功能

         select * from phbs_nurse_t order by CONVERT(nurse_name USING gbk)

  • 序号转int 排序

          select server_id from cardserver where game_id = 1 order by CAST(server_id as SIGNED) desc limit 10;

  • 开启慢查询统计

      show variables like 'slow_query%';
      set global slow_query_log='ON'; 
      set global long_query_time=5; 
      show variables like 'long_query_time%';

  • 查看正在执行的SQL语句,干掉正在执行的SQL

       show processlist;
       kill 14568;

  •   Navicat 开启事务

         START transaction ;
        COMMIT;   rollback; 

  • 使用UUID

    update 表名 set id = REPLACE(UUID(),'-','') where id is null or id ='';

  • 快速创建一个备份表的结构

create table table_bak select * from table where 1=2 

  • 创建函数报错,log_bin_trunc...

# 1418 -This function has none of DETERMINISTIC,NOSQL,or READS SQL DATA in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable)
set global log_bin_trust_function_creators=1;

  • 临时表操作

CREATE TEMPORARY TABLE 表名_TMP
select * from 实例名.表名_;
-- 增加索引
ALTER TABLE 表名_TMP ADD INDEX index_lxid(`lxid`);

记录表 查询最新一条记录的更新人和更新时间

1 创建存储方法 SPLIT_STR

CREATE DEFINER=`root`@`%` FUNCTION `SPLIT_STR`(
  x VARCHAR(255),
  delim VARCHAR(12),
  pos INT
) RETURNS varchar(255) CHARSET utf8
BEGIN
    RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
       LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
       delim, '');
END

SELECT
    id,
    NAME,
    GROUP_CONCAT( DISTINCT other_id ORDER BY id ASC ) otherId,
    GROUP_CONCAT( DISTINCT other_name ORDER BY id ASC ) otherName,
    max( modify_dt ) modifyDt,
    SPLIT_STR ( max( concat( modify_dt, '&', modifier ) ), '&', 2 ) modifier

FROM
    USER INNER JOIN user_log ON...
WHERE
    USER.is_del = '0' 
GROUP BY
    id

SPLIT_STR :函数
BEGIN
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
       LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
       delim, '');
END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhchyun2008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值