zoukankan      html  css  js  c++  java
  • mysql的cpu飙升原因及处理

     Mysql 批量杀死进程

    正常情况下kill id,即可,但是有时候某一异常连接特别多的时候如此操作会让人抓狂,下面记录下小方法:

    use information_schema;
    
    select concat('kill ',id,';') from processlist where host like '192.168.0.1%' into outfile '/tmp/kill.sql';
            函数                                          字段        ip地址                  
    source /tmp/kill.sql

     ###################################################

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

    1
    2
    3
    4
    5
    6
    7
    8
    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.查看所有数据库各表容量大小

    1
    2
    3
    4
    5
    6
    7
    8
    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库容量大小

    1
    2
    3
    4
    5
    6
    7
    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库各表容量大小

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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;

    #################################################################

    Mysql 备份单表数据

    DROP TABLE IF EXISTS B;
    CREATE TABLE B LIKE A;
    INSERT INTO B SELECT * FROM A;

    Mysql 统计表的行数

    # mysqlshow -uroot -p  mysql -v -v
    统计mysql数据库所有表的列数和行数
    
    select count(*) from B.t1
    统计B数据库t1表的行数

    Mysql 插入一个字段 id自增并设置为主键

    alter table t1 ADD id INT(16) NOT NULL PRIMARY KEY AUTO_INCREMENT first;
  • 相关阅读:
    SourceTree Win10 安装过程及配置
    Laravel 5.5 官方推荐 Nginx 配置学习
    Laravel 获取当前 Guard 分析 —源自电商购物车的实际需求
    Laravel Query Builder 复杂查询案例:子查询实现分区查询 partition by
    Laravel Scheduling Package
    Homestead 中使用 laravel-mix 问题汇总
    iBrand 教程:Git 软件安装过程截图
    使用 Satis 搭建私有的 Composer 包仓库
    Windows + Homestead 5 搭建 Laravel 开发环境
    Homestead 安装 phpMyAdmin 作为数据库管理客户端 — Laravel 实战 iBrand API 教程
  • 原文地址:https://www.cnblogs.com/wuhg/p/11730664.html
Copyright © 2011-2022 走看看