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
相关推荐
热爱运维的小七20 分钟前
MongoDB 内存管理避坑指南:解决高占用、页错误等核心问题,让数据库性能翻倍
数据库·mongodb
冉冰学姐2 小时前
SSM公办小学网络报名系统f3d3p(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·ssm 框架·公办小学网络报名系统·教育信息化
叡鳍3 小时前
hive---HQL查询
数据库
vortex53 小时前
谷歌黑客语法挖掘 SQL 注入漏洞
android·数据库·sql
九河云4 小时前
软件开发平台 DevCloud
运维·服务器·数据库·科技·华为云
wind_one15 小时前
7.基础--SQL--DDL-数据类型及案例
数据库·sql
l1t6 小时前
利用DeepSeek改写SQLite版本的二进制位数独求解SQL
数据库·人工智能·sql·sqlite
QT 小鲜肉6 小时前
【QT/C++】Qt定时器QTimer类的实现方法详解(超详细)
开发语言·数据库·c++·笔记·qt·学习
研究司马懿6 小时前
【ETCD】ETCD常用命令
网络·数据库·云原生·oracle·自动化·运维开发·etcd
-指短琴长-6 小时前
MySQL快速入门——基本查询(下)
android·mysql·adb