zoukankan      html  css  js  c++  java
  • mysql 常用语句

    一、查询:

    truncate alerts;  #清空表数据
    select
    count(*) from win_cdr_trunk_201807_oneself where time_start<'2018-08-01 00:00:00'; #计算2018-08-01 00:00:00之前数据总数
    select count(*) from   win_cdr201806 where start_year='2018' and start_month='06'; #计算2018-06月份数据总数

     备份数据库

    mysqldump --set-gtid-purged=off  -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod win_agmonitor > win_agmonitor.sql
    mysqldump --set-gtid-purged=off -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod rep_tmp_time > rep_tmp_time.sql

    mysql -u root -pHaixue.*X_864.o8 ccod < win_agmonitor.sql
    mysql -u root -pHaixue.*X_864.o8 ccod < rep_tmp_time.sql

    mysqldump --set-gtid-purged=off  -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod win_agmonitor > win_agmonitor.sql

     查询所有存储过程,并生成删除语句

    select concat('drop procedure if exists ',b.SPECIFIC_NAME,';')as yuju from   (select  SPECIFIC_NAME  from information_schema.routines 
    where routine_schema in ('0802test','0903beifen') and ROUTINE_TYPE = 'PROCEDURE') b;

    1.查看所有数据库容量大小

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

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

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

      

    3.查看指定数据库容量大小

    例:查看mysql库容量大小

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

      

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

    例:查看mysql库各表容量大小

    select
    table_schema as '数据库',
    table_name as '表名',
    table_rows as '记录数',
    truncate(data_length/1024/1024, 2) as '数据容量(MB)',
    truncate(index_length/1024/1024, 2) as '索引容量(MB)'
    from information_schema.tables
    where table_schema='mysql'
    order by data_length desc, index_length desc;
  • 相关阅读:
    Android入门第六篇之ListView (一)
    STL 二分查找三兄弟(lower_bound(),upper_bound(),binary_search())
    fastjson 之常见的数据类型与json的相互转换
    Jetty:配置安全
    xml文件格式例如以下
    《编程珠玑》---笔记。浏览此文,一窥此书。
    【Github教程】史上最全github用法:github入门到精通
    SSL连接建立过程分析(1)
    ant 安装
    GMM的EM算法实现
  • 原文地址:https://www.cnblogs.com/chimeiwangliang/p/9838136.html
Copyright © 2011-2022 走看看