zoukankan      html  css  js  c++  java
  • mysql

    查询表信息

    --  查询自动提交
    show VARIABLES like 'autocommit';
    -- 修改自动提交
    set autocommit=1;
    -- 查看表信息
    show table status like 'student';

     性能剖析

    -- 性能剖析开启状态
    show VARIABLES like 'profiling';
    -- 性能剖析
    show profiles;

    比如先执行一条语句select * from user;

    再执行show profiles; 可以看到结果中有语句的执行时间

     接下来执行

    show profile for query 35;

    可以看到具体的执行步骤占用时间

    不过这里是按照顺序排序的,要想按耗时排序,可以使用以下语句

    select state,sum(duration) as Total_R,
    round(100*sum(duration)/
    (select sum(duration) from information_schema.PROFILING
    where query_id=35),2)as Pct_R,
    count(*) as Calls,
    sum(duration)/count(*) as "R/Call"
    from information_schema.PROFILING
    where query_id=35
    GROUP BY state
    ORDER BY Total_R DESC;

     show CREATE table + 表名

     查询索引

    show index from 表名;

     查询状态

    show full processlist;

     

     Command列Query表示线程正在执行查询或者正在将结果发送给客户端。

     使用show status

    show status WHERE variable_name like 'HANDLER%' or variable_name like 'created%';

    使用show PROCESSLIST

    mysql复制

    主库:10.15.4.155

    从库:10.15.4.156

    在主库和从库创建账号并赋予复制权限

    grant replication slave,replication client on *.* to repl@'10.15.4.%' identified by 'xxx'

    先查看配置

    which mysqld

    结果是/usr/sbin/mysqld

    再运行

    /usr/sbin/mysqld --verbose --help | grep -A 1 'Default options'

    结果是

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

    编辑主库的/etc/my.cnf,加入以下配置

    log_bin=mysql-bin
    server_id=10

    重启MySQL,查看主库状态

    show master status;

    编辑从库的配置

    log_bin=mysql-bin
    server_id=2
    relay_log=/var/lib/mysql/mysql-relay-bin
    log_slave_updates=1

     连接主库

    change master to master_host='10.15.4.155',
    master_user='repl',
    master_password='xxxx',
    master_log_file='mysql-bin.000001',
    master_log_pos=0;

    查看从库状态

    show slave status;

    启动复制

    start slave;

    再次查看状态

    查看主库进程

    show processlistG

    查看从库进程

  • 相关阅读:
    word20170108逛景点 Sightseeing有用的词和句子
    c# List 分页问题
    VUE界面,this.form.xxx=1赋值后,界面效果没有变化
    SQL Server使用索引视图来实现“物化视图”
    .NET CORE 实现异步处理
    当请求接口提示网络错误Error:Network Error的时候
    SheetJS js-xlsx :js实现导出Excel模板
    增加索引分析
    聚集索引与非聚集索引的总结
    Dynamics CRM-无法识别安全令牌的颁发者,若要接受来自此颁发者的安全令牌,请将 IssuerNameRegistry 配置为返回此颁发者的有效名称
  • 原文地址:https://www.cnblogs.com/uptothesky/p/8890670.html
Copyright © 2011-2022 走看看