search
HomeDatabaseMysql TutorialMysql数据状态监听探讨(攒人品)_MySQL

bitsCN.com

年会前攒人品,你懂得!

应用场景:

长时间运行程序,需要几乎整表查询Mysql,还得在可容忍范围内响应数据变化。

 

方案一:通过Mysql自带的表更新时间

查询方案:SELECT TABLE_NAME,UPDATE_TIME FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA='Palas_V4';

存在问题:innodb 不支持,需要更换数据库引擎;只支持表级判断(可以接受)。

优点:查询速度快。

变种解决方案:1、创建触发器,在表执行update/insert/delete 时更新UPDATE_TIME为当前时间戳;2、在数据库访问接口处增加程序逻辑来更新该时间戳。

 

方案二:在所有行增加更新时间戳字段

查询方案:判断是否修改只需查询该表最大的updatetime,增量更新仅需要查询大于上次查询时间的数据。

存在问题:表每行会增加4bytes的空间消耗,更新时间戳问题可通过mysql自身解决;不支持delete操作,如要删除需要增加是否有效字段来改变状态。

优点:可以做到行级的更新。

 

方案三:读取Mysql文件的系统修改时间

查询方案:获取E:/SqlData/data/Palas_V4/ Media.frm 的系统修改时间

存在问题:需要在Mysql所在服务器操作,或者需要远程访问它的权限,可能导致安全问题;只支持表级判断。

优点:速度快,不需要额外表空间或增加mysql负载。

变种解决方案:1、在Mysql所在服务器创建监控服务提供数据库状态信息。

 

方案选型:

优缺点分析:

方案一与二均需对数据库做出相应修改,一所做修改对业务逻辑不会有影响,但对Mysql的操作会增加一倍(实际修改需要8(可能是4)个字节每次的数据量)无网络传输;程序实现逻辑简单;在数据修改量不大的情况话对性能几乎没有影响,但修改后查询开销大。方案二对表空间的增长会变大,对业务逻辑会有较小的影响(不再支持删除),部分表还需要增加字段判断状态,修改后查询开销较小。方案三性能与一相差不大,但需要额外编程提供状态查询,时间和硬盘IO会增大(不显著)。

选型:

       根据实际情况,排除暂时不会遇到的问题,优先级排列如下:

方案三 -> 方案二 –> 方案一 (方案一排最后是由于太多触发器会导致表维护困难,更新引擎将使数据库性能降低)

 

Mysql 开启独立表空间:

1. 停掉mysql:  /etc/init.d/mysqld stop  

2. 改my.cnf的配置文件: innodb-file-per-table=1

3. 备份使用innodb引擎的数据库:  mysqldump -u tg -p tg >/home/6fan/tg.sql;  

4. 删除使用innodb的数据库,以及日志文件 。如果不删除使用innodb的数据库文件夹,启动不了innodb引擎。

5. 启动mysql : /etc/init.d/mysqld start 

6. 导入数据库: mysql -u root -p 

有图形化管理工具的在修改配置文件后直接备份需要监听的数据库,然后删除后恢复也是可以的。

 

构建文件监听与数据提供服务:

1、 在mysql服务器开启文件监听服务,提供get put方法(仅提供状态,数据需要自己查)

2、 Get方法在全局数据提供服务启动时调用,Put方法为主动向接受者声明哪些需要同步

 

构建全局数据提供服务:(Web Api 支持json和xml格式)

1、 启动时使用get获取所有文件状态;

2、 接受put的数据以启用数据更新(可改为查询时主动get);

3、 有调用者时返回数据;

4、 对数据进行压缩处理;保存以便传输

 

本文来自 NewIdea 的博客,作者 ziyunhx 。

原文地址:http://www.cnblogs.com/NewIdea/p/MysqlStatus.html

转载请注明出处,否则拒绝转载!

bitsCN.com
Statement
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
Reduce the use of MySQL memory in DockerReduce the use of MySQL memory in DockerMar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared libraryHow to solve the problem of mysql cannot open shared libraryMar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin)Run MySQl in Linux (with/without podman container with phpmyadmin)Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overviewWhat is SQLite? Comprehensive overviewMar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guideRunning multiple MySQL versions on MacOS: A step-by-step guideMar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools