• mysql数据库 操作常用命令


    查看数据库文件大小

    1. SELECT
    2. file_name,
    3. concat(TOTAL_EXTENTS, 'M') as 'FIle_size'
    4. FROM
    5. INFORMATION_SCHEMA.FILES
    6. order by
    7. TOTAL_EXTENTS DESC;

    查看所有数据库容量大小

    1. select
    2. table_schema as '数据库',
    3. sum(table_rows) as '记录数',
    4. sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
    5. sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
    6. from information_schema.tables
    7. group by table_schema
    8. order by sum(data_length) desc, sum(index_length) desc;

    查看所有数据库各表容量大小

    1. select
    2. table_schema as '数据库',
    3. table_name as '表名',
    4. table_rows as '记录数',
    5. truncate(data_length/1024/1024, 2) as '数据容量(MB)',
    6. truncate(index_length/1024/1024, 2) as '索引容量(MB)'
    7. from information_schema.tables
    8. order by data_length desc, index_length desc;

    查看指定数据库容量大小

    例:查看库容量大小

    1. select
    2. table_schema as '数据库',
    3. sum(table_rows) as '记录数',
    4. sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
    5. sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
    6. from information_schema.tables
    7. where table_schema='db_name';

    查看指定数据库各表容量大小

    例:查看库各表容量大小

    1. select
    2. table_schema as '数据库',
    3. table_name as '表名',
    4. table_rows as '记录数',
    5. truncate(data_length/1024/1024, 2) as '数据容量(MB)',
    6. truncate(index_length/1024/1024, 2) as '索引容量(MB)'
    7. from information_schema.tables
    8. where table_schema='db_name'
    9. order by data_length desc, index_length desc;

    表数量对比

    1. SELECT
    2. TABLE_SCHEMA,
    3. count(*)
    4. FROM information_schema.TABLES
    5. WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', 'performance_schema')
    6. GROUP BY TABLE_SCHEMA
    7. ORDER BY 2 DESC;

    触发器对比

    1. SELECT
    2. TRIGGER_SCHEMA,
    3. count(*)
    4. FROM information_schema.TRIGGERS
    5. WHERE TRIGGER_SCHEMA NOT IN ('information_schema', 'mysql', 'performance_schema')
    6. GROUP BY TRIGGER_SCHEMA
    7. ORDER BY 2 DESC;

    字符集对比

    SELECT SCHEMA_NAME,DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA;
    

    表中数据量对比

    查询对比2917-07-08日之前表的数据量看两库是否一致。

    1. select 'mobile_card.wepay_wallet_record' `name`, count(*) CNT from mobile_card.wepay_wallet_record where create_time <'2017-07-08' union all
    2. select 'mobile_card.mcc_wescore_record' `name`, count(*) CNT from mobile_card.mcc_wescore_record where id <100712118 union all
    3. select 'mobile_card.mcc_customer_grant' `name`, count(*) CNT from mobile_card.mcc_customer_grant where id <39691660 union all
    4. select 'mobile_card.mcc_credit_score' `name`, count(*) CNT from mobile_card.mcc_credit_score where id <35485079 union all
    5. select 'mobile_card.mcc_consume_repayment' `name`, count(*) CNT from mobile_card.mcc_consume_repayment where id <29256981 union all
    6. select 'mobile_card.mcc_customer' `name`, count(*) CNT from mobile_card.mcc_customer where id <23204782 union all
    7. select 'mobile_card.mcc_repayment_record' `name`, count(*) CNT from mobile_card.mcc_repayment_record where id <26479142 union all
    8. select 'mobile_card.mcc_credit_card' `name`, count(*) CNT from mobile_card.mcc_credit_card where id <15473828 union all
    9. select 'mobile_card.mcc_customer_card' `name`, count(*) CNT from mobile_card.mcc_customer_card where id <3509303 ;

    创建数据库命令

    CREATE DATABASE IF NOT EXISTS db_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
    
    GRANT ALL PRIVILEGES ON *.* TO 'app_rw'@'%' IDENTIFIED BY PASSWORD ""


     

     

  • 相关阅读:
    Python分享之路径与文件 (os.path包, glob包)
    Linux基础知识,这里有很多内容可以看看~
    EFCore学习笔记(3)——实体属性
    关于高速PCB设计的串扰知识,这篇文章讲清楚了
    跨模态检索论文阅读:(ViLT)Vision-and-Language Transformer Without Convolution or Region Supervision
    Linux 网络编程项目 —— FTP 网盘
    行业春寒回暖,持续承压的酒店企业于何处破局?
    JavaScript分支语句(if、三元表达式、switch)
    Apache HTTPD 漏洞复现
    小赢科技,寻找金融科技核心价
  • 原文地址:https://blog.csdn.net/m0_60379130/article/details/127651534