MySQL日常操作记录

1.查看MySQL版本

sql 复制代码
select version();

2.快速复制表结构,不包含相关主键及约束

sql 复制代码
create table user_test as select * from user where 1=2;

3.uuid

sql 复制代码
select uuid(),uuid_short();

4.替换uuid()里的'-'为''

sql 复制代码
select replace(uuid(),'-','');

5.md5摘要

sql 复制代码
select md5(uuid()),md5('123456');

6.复制数据

sql 复制代码
insert into user_test(id, name, age, city) 
select replace(uuid(),'-',''),name,age,'vue3' from user;

insert into user_test(id, name, age, city) 
select md5(uuid()),name,25,city from user;

7.ip4地址转整数,整数转换ip4地址

sql 复制代码
select INET_ATON('127.0.0.1') address_2_number,
INET_NTOA(2130706433) number_2_address;

8.删除数据,不允许边查询边删除/更新。

sql 复制代码
delete from user_test where id in (select id from user_test where parent_id='75e2f86d0a2c11ee89c70242ac110002');
-- [HYO00][1093] You can't specify target table 'user_test' for update in FROM clause
delete from user_test where id in (select id from (select id from user_test where parent_id='75e2f86d0a2c11ee89c70242ac110002') t);

9.查询数据库blob字段

sql 复制代码
select convert(remark using utf8) from user

10.关联查询,没有数据的统计为0,构造基础数据,子查询或连接查询实现

sql 复制代码
select l.province,ifnull(
    (select biz.num from (
        select '北京' as province,100 as num
        union all
        select '深圳' as province,208 as num
    ) biz where biz.province = l.province),0) as num
from (select '北京' as province
      union all
      select '上海'
      union all
      select '广州'
      union all
      select '深圳') l
相关推荐
先吃饱再说11 小时前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
Nturmoils11 小时前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend13 小时前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent
这个DBA有点耶14 小时前
SQL改写进阶:标量子查询的“隐形代价”与消除实战
数据库·mysql·架构
smallyoung15 小时前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
parade岁月15 小时前
MySQL JOIN解析:朴实无华但食之有味
数据库·后端
用户31693538118316 小时前
MySQL服务无法启动问题解决全记录
数据库
vivo互联网技术19 小时前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
数据技术说19 小时前
MySQL 迁移实战——如何实现真正的"零改造"平滑切换
mysql
倔强的石头_1 天前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库