• MySQL


    目录

    • mysql 使用insert-select快速造出大量测试数据
    • 查看mysql数据库容量

    1 mysql 使用insert-select快速造出大量测试数据

    insert-select的原理是将表中数据查出后,再次插入数据库,这样数据就会成倍增长。
    
    • use 库建表
    CREATE TABLE `review` (
    `review_id` INT(11) NOT NULL AUTO_INCREMENT,
    `movie_id` INT(11) NOT NULL,
    `content` VARCHAR(1024) NOT NULL,
    PRIMARY KEY (`review_id`)
    )
    COLLATE='utf8_general_ci'
    ENGINE=InnoDB;
    
    • 首先使用如下语句插入10条数据,主键任其自增
    insert into review(movie_id,content) values(1,now());
    
    • 然后使用insert-select方法成倍插入数据
    insert into review(movie_id,content) select movie_id,content from review;
    
    • 查看review表数据行数
    select count(*) from review;
    

    2 查看mysql数据库容量

    • 查询所有数据库的总大小
    use information_schema;
    select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
    
    • 统计一下所有库数据量
    # 每张表数据量=AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH
    SELECT
    SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb
    FROM information_schema.TABLES;
    
    • 统计每个库大小:
    SELECT
    table_schema,SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb
    FROM information_schema.TABLES group by table_schema;
    
    • 查看指定数据库的大小,比如说:数据库test
    use information_schema;
    select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='test';
    
    • 查看所有数据库各容量大小
    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;
    
    • 查看所有数据库各表容量大小
    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;
    
    • 查看指定数据库容量大小
    # 例:查看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'; 
    
    • 查看指定数据库各表容量大小
    例:查看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;
    

    参考文档:

  • 相关阅读:
    运算符优先级口诀
    [转] 从最大似然到EM算法浅解
    推荐系统实践整体化总结
    Python-函数
    Python-dict/set
    Python-条件、循环、
    Python-list and tuple
    优先级顺序表
    8.1python类型注解
    9.redis-CacheCloud
  • 原文地址:https://www.cnblogs.com/xiaoqshuo/p/14371019.html
Copyright © 2020-2023  润新知