zoukankan      html  css  js  c++  java
  • 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;
    

    参考文档:

  • 相关阅读:
    leetcode 673. 最长递增子序列的个数 java
    leetcode 148. 排序链表 java
    leetcode 98. 验证二叉搜索树 java
    leetcode 29. 两数相除 java
    leetcode 234. 回文链表 java
    Valid Palindrome LeetCode Java
    Single Number II LeetCode Java
    Single Number LeetCode java
    Search in Rotated Sorted Array II LeetCode Java
    Search in Rotated Sorted Array leetcode java
  • 原文地址:https://www.cnblogs.com/xiaoqshuo/p/14371019.html
Copyright © 2011-2022 走看看