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
相关推荐
陈天伟教授3 小时前
人工智能训练师认证教程(2)Python os入门教程
前端·数据库·python
Elastic 中国社区官方博客4 小时前
Elasticsearch:在分析过程中对数字进行标准化
大数据·数据库·elasticsearch·搜索引擎·全文检索
聪明努力的积极向上4 小时前
【MYSQL】字符串拼接和参数化sql语句区别
数据库·sql·mysql
代码or搬砖4 小时前
RBAC(权限认证)小例子
java·数据库·spring boot
神仙别闹4 小时前
基于QT(C++)实现学本科教务系统(URP系统)
数据库·c++·qt
2301_768350234 小时前
MySQL为什么选择InnoDB作为存储引擎
java·数据库·mysql
上海蓝色星球4 小时前
迈向智慧电网新纪元:上海蓝色星球数字孪生变电主子站系统
运维·数据库
是大芒果4 小时前
数据库表设计
数据库
哥哥还在IT中4 小时前
MySQL order by 如何优化
数据库·mysql
积跬步,慕至千里5 小时前
postgre数据库大批量快速导出方法总结
数据库·postgres