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
相关推荐
夜泉_ly1 小时前
MySQL -安装与初识
数据库·mysql
qq_529835352 小时前
对计算机中缓存的理解和使用Redis作为缓存
数据库·redis·缓存
月光水岸New5 小时前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6755 小时前
数据库基础1
数据库
我爱松子鱼5 小时前
mysql之规则优化器RBO
数据库·mysql
chengooooooo5 小时前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser6 小时前
【SQL】多表查询案例
数据库·sql
Galeoto6 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)7 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231117 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql