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
相关推荐
玄同76528 分钟前
SQLite + LLM:大模型应用落地的轻量级数据存储方案
jvm·数据库·人工智能·python·语言模型·sqlite·知识图谱
吾日三省吾码30 分钟前
别只会“加索引”了!这 3 个 PostgreSQL 反常识优化,能把性能和成本一起打下来
数据库·postgresql
chian-ocean31 分钟前
百万级图文检索实战:`ops-transformer` + 向量数据库构建语义搜索引擎
数据库·搜索引擎·transformer
那个村的李富贵1 小时前
解锁CANN仓库核心能力:50行代码搭建国产化AIGC图片风格迁移神器
mysql·信息可视化·aigc·cann
小Tomkk1 小时前
数据库 变更和版本控制管理工具 --Bytebase 安装部署(linux 安装篇)
linux·运维·数据库·ci/cd·bytebase
qq_12498707531 小时前
基于JavaWeb的大学生房屋租赁系统(源码+论文+部署+安装)
java·数据库·人工智能·spring boot·计算机视觉·毕业设计·计算机毕业设计
倒流时光三十年2 小时前
SpringBoot 数据库同步 Elasticsearch 性能优化
数据库·spring boot·elasticsearch
码农小卡拉2 小时前
深入解析Spring Boot文件加载顺序与加载方式
java·数据库·spring boot
怣502 小时前
MySQL多表连接:全外连接、交叉连接与结果集合并详解
数据库·sql
wjhx3 小时前
QT中对蓝牙权限的申请,整理一下
java·数据库·qt