MySQLの日々の運用記録

ここに画像の説明を挿入

1.MySQLのバージョンを確認する

select version();

2. 関連する主キーと制約を除いて、テーブル構造をすばやくコピーします。

create table user_test as select * from user where 1=2;

3.uuid

select uuid(),uuid_short();

4. uuid() の「-」を「」に置き換えます。

select replace(uuid(),'-','');

5.md5の概要

select md5(uuid()),md5('123456');

6.データのコピー

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 アドレスを整数に変換します

select INET_ATON('127.0.0.1') address_2_number,
INET_NTOA(2130706433) number_2_address;

8. データの削除 クエリ中の削除/更新は許可されません。

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 フィールドのクエリ

select convert(remark using utf8) from user

10. 相関クエリ、データなしの統計が 0、基本データの構築、サブクエリまたは接続クエリの実装

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

おすすめ

転載: blog.csdn.net/weixin_43275277/article/details/131779145