Home > Database > Mysql Tutorial > body text

MySQL performance, monitoring and disaster recovery

黄舟
Release: 2017-02-21 10:27:19
Original
1260 people have browsed it



Monitoring solution:

up.time    http://www.php.cn/    收费
    Cacti        http://www.php.cn/
    KDE System Guard(KSysGuard) 
                    http://www.php.cn/
    Gnome System Monitor
                    http://www.php.cn/
    Nagios    http://www.php.cn/
    Shinken  http://www.php.cn/  (个人觉得比nagios好用)
    Sun Management Center
                    http://www.php.cn/
    MySQL Enterprise Monitor
                    http://www.php.cn/
Copy after login


Linux and UNIX systems Monitoring tool

ps           系统进程
        top         cpu使用率排序的活动进程
        vmstat    显示分页、内存、块传输、cpu活动相关
        uptime   显示系统运行时间及1、5、15分钟系统平均负载
        free         显示内存使用率
        iostat      显示平均磁盘活动和处理器负载    centos: yum install sysstat
        sar           系统活动报告、允许收集和报告各种系统活动
        pmap      显示各种进程分别占用内存情况
        mpstat    多处理器系统的cpu使用率    centos: yum install sysstat
        netstat    网络活动
        cron         定时进程执行系统(计划任务)
Copy after login


Set and read system variables

SHOW [GLOBAL | SESSION] VARIABLES;
    SET [GLOBAL | SESSION]  <variable_name> = <value>;
    SET [@@global. | @@session. | @@]  <variable_name>=<value>;
    SHOW STATUS;
    SHOW SESSION STATUS;
    SHOW GLOBAL STATUS;
Copy after login


SQL command

SHOW INDX FROM <table>    //显示指定表的索引基数统计信息
    SHOW PLUGINS                         //显示所有已知插件列表
    SHOW [FULL] PROCESSLIST      //显示系统上运行的所有线程。
    SHOW  [GLOBAL | SESSION] STATUS    //显示所有系统变量值
    SHOW  TABLE [FROM <db>]  STATUS  //显示给定数据库的表的详情
    SHOW [GLOBAL | SESSION] VARIABLES  //显示系统变量
Copy after login

In order To view less information, you can use the like '' clause. Standard MySQL regular expression symbols and control symbols can be used in the like statement

SHOW ENGINE <engine_name> LOGS    //显示指定存储引擎的日志信息
    SHOW ENGINE <engine_name> STATUS //显示指定存储引擎状态信息
    SHOW ENGINES                        //显示所有可用的存储引擎的列表及状态
    SHOW BINARY LOGS                //显示服务器二进制LOG列表
    SHOW RELAYLOG EVENTS [IN &#39;<log_file>&#39;]  [FROM <pos>]  [LIMIT [<offset>, ] <row count>]
                                                        //仅限制查看Slave上的中继日志
    SHOW MASTER STATUS           //显示Master当前配置,显示当前二进制日志文件,文件位置等
    SHOW SLAVE HOSTS                //使用--report-host 选项显示连接到Master的slave列表
    SHOW SLAVE STATUS               //显示复制中slave的系统状态
Copy after login

MySQL GUI Tool

MySQL Administrator
    MySQL Query Browser
    MySQL Migration Toolkit    //用于自动从其他数据库系统上迁移数据
Copy after login

Third-party tools

MySAR 系统活动报告
    mytop    监控线程统计信息和Mysql常规性能统计信息
    innotop   用于监控InnoDB性能和MySQL服务器
    MONyog  (MySQL Monitor and Advisor) mysql监控工具,主动监控方案
    MySQL Benchmark套件 MySQL基准测试
        ./run-all-tests --server=mysql --cmp=mysql --user=root --socket=<socket>
Copy after login


##Measure database performance

EXPLAIN   分析关于如何执行SELECT语句的信息
    ANALYZE [ LOCAL |  NO_WRUTE_TO_BINLOG ] TABLE    
        #[ LOCAL |  NO_WRUTE_TO_BINLOG ] 可防止命令写入二进制日志。
    SHOW INDEX FROM  TABLE
    OPTIMIZE  [ LOCAL |  NO_WRUTE_TO_BINLOG ] TABLE <table_list>
        #重构一个或多个表的数据结构,整理存储空间
    SHOW FULL PROCESSLIST;  查看所有进程信息
Copy after login



Database Optimization

1. Use indexes carefully and effectively

2. Use normalization (normalization), but don’t overdo it

3. Use the correct storage engine

Alter table t1 ENGINE=MEMORY;


Best practices to improve performance

1 , everything is slow (check the problem)

* Check the hardware

* Improve the hardware environment (such as adding a hard disk)

* Consider migrating data to a separate disk

* Check whether the operating system configuration is correct

* Consider migrating some applications to other servers

* Consider Replication that can be scaled out

* Optimize server performance


2. Slow query

* Normalized database schema

* Use EXPLAIN to identify missing or incorrect indexes

* Use the benchmark() function to test partial queries

* Consider rewriting the query

* Use views for standard queries

* Enable Query Cache


3. Slow application

* Enable Query Cache

* Consider and optimize storage Engine

* Confirm if it is a server or operating system issue

* Define a baseline for the application and compare it to a known baseline

) queries written inside the program and maximize their performance

* Divide and conquer - check only one part at a time

* Use partitioning classes to disperse data

* Check individual partitions Index


4. Slow copy

* 确保网络运行状况最佳

* 确保服务器配置正确

* 优化数据库

* 限制 Master 的更新

* 将数据读取划分到多个Slave中

* 检查Slave 的复制延迟

* 定期维护日志(二进制日志和中继日志)

* 在带宽有限的情况下,使用压缩

* 使用包容性和排他性日志选项,最小化复制内容



数据引擎的优化和监控

MyISAM实用工具

* myisam_ftdump: 显示全文索引信息

* myisamchk : 执行MyISAM 表的分析(只能在脱机状态使用)

* myisamlog : 查看MyISAM 表的更改日志

* myisampack:压缩表以减少存储量


Key Cache

1、预加载Key Cache

#将salary表的索引加载到key cache中,ignore leaves: 表明只加载索引的非叶子节点,可通过修改表的方式从Key cache中移除相关索引

mysql> load index into cache salaries ignore leaves;

2、使用多个Key Cache

#使用耳机主缓存

mysql> set global emp_cache.key_buffer_size = 128*1024; //128K
            mysql> cache index salaries in emp_cache;
            mysql> set global emp_cache.key_buffer_size=0;
Copy after login


#to confirm whether a second -level cache exists

This cache In a file, use the init-file= command in the [mysqld] section of the mysql configuration file to execute the file.



The above is the content of MySQL performance, monitoring and disaster recovery. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template