search
HomeDatabaseMysql Tutorialmysql数据库数据变化实时监控

mysql数据库数据变化实时监控

May 15, 2018 pm 04:50 PM
mysqlwarningVarietyreal timedatadatabasemonitor

mysql数据库数据变化实时监控

相关mysql视频教程推荐:《mysql教程

Warning : fopen(/home1/vhost/vh499565/www/blog/wp-content/plugins/devformatter/geshi/geshi/mysql.php) [function.fopen]: failed to open stream: No such file or directory in /home1/vhost/vh499565/www/www_shaozhuqing/wp-content/plugins/devfor
Warning:  fopen(/home1/vhost/vh499565/www/blog/wp-content/plugins/devformatter/geshi/geshi/mysql.php) [function.fopen]: failed to open stream: No such file or directory in /home1/vhost/vh499565/www/www_shaozhuqing/wp-content/plugins/devformatter/devgeshi.php on line 103Warning:  fopen(/home1/vhost/vh499565/www/blog/wp-content/plugins/devformatter/geshi/geshi/mysql.php) [function.fopen]: failed to open stream: No such file or directory in /home1/vhost/vh499565/www/www_shaozhuqing/wp-content/plugins/devformatter/devgeshi.php on line 103Warning:  fopen(/home1/vhost/vh499565/www/blog/wp-content/plugins/devformatter/geshi/geshi/mysql.php) [function.fopen]: failed to open stream: No such file or directory in /home1/vhost/vh499565/www/www_shaozhuqing/wp-content/plugins/devformatter/devgeshi.php on line 103Warning:  fopen(/home1/vhost/vh499565/www/blog/wp-content/plugins/devformatter/geshi/geshi/mysql.php) [function.fopen]: failed to open stream: No such file or directory in /home1/vhost/vh499565/www/www_shaozhuqing/wp-content/plugins/devformatter/devgeshi.php on line 103

对于二次开发来说,很大一部分就找找文件和找数据库的变化情况 对于数据库变化。还没有发现比较好用的监控数据库变化监控软件。 今天,我就给大家介绍一个如何使用mysql自带的功能监控数据库变化

1、打开数据库配置文件my.ini (一般在数据库安装目录)(D:\MYSQL)

2、在数据库的最后一行添加 log=log.txt  代码

3、重启mysql数据库

4、去数据库数据目录 我的是(D:\MYSQL\data) 你会发现多了一个log.txt文件 我的是在C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\data

测试:

1、对数据库操作

2、查看log.txt文件内容 如果发现有变化说明你就可以监控到mysql数据库的变化 数据库的查询 删除 更新 插入都可以查到 希望本篇文章可以帮助大家更快的二次开发 ^_^

日志文件类型概述:?? 
1.错误日志?? 记录启动、运行或停止mysqld时出现的问题。
My.ini配置信息:
#Enter a name for the error log file.?? Otherwise a default name will be used.
#log-error=d:/mysql_log_err.txt
2.查询日志????记录建立的客户端连接和执行的语句。
My.ini配置信息:
#Enter a name for the query log file. Otherwise a default name will be used.
#log=d:/mysql_log.txt
3.更新日志?? 记录更改数据的语句。不赞成使用该日志。
My.ini配置信息:
#Enter a name for the update log file. Otherwise a default name will be used.
#log-update=d:/mysql_log_update.txt
4.二进制日志????记录所有更改数据的语句。还用于复制。
My.ini配置信息:
#Enter a name for the binary log. Otherwise a default name will be used.
#log-bin=d:/mysql_log_bin
5.慢日志????记录所有执行时间超过long_query_time秒的所有查询或不使用索引的查询。
My.ini配置信息:
#Enter a name for the slow query log file. Otherwise a default name will be used.
#long_query_time =1
#log-slow-queries= d:/mysql_log_slow.txt
在linux下:
Sql代码
??? 1. # 在[mysqld] 中輸入
?? 2. #log
?? 3. log-error=/usr/local/mysql/log/error.log
?? 4. log=/usr/local/mysql/log/mysql.log
?? 5. long_query_time=2
?? 6. log-slow-queries= /usr/local/mysql/log/slowquery.log 
?# 在[mysqld] 中輸入 #log log-error=/usr/local/mysql/log/error.log log=/usr/local/mysql/log/mysql.log long_query_time=2 log-slow-queries= /usr/local/mysql/log/slowquery.log
??windows下:
Sql代码
??? 1. # 在[mysqld] 中輸入
?? 2. #log
?? 3. log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log"
?? 4. log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log"
?? 5. long_query_time=2
?? 6. log-slow-queries= "E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log" 
?# 在[mysqld] 中輸入 #log log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log" log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log" long_query_time=2 log-slow-queries= "E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log"
???开启慢查询
long_query_time =2 --是指执行超过多久的sql会被log下来,这里是2秒
log-slow-queries= /usr/local/mysql/log/slowquery.log --将查询返回较慢的语句进行记录
?log-queries-not-using-indexes = nouseindex.log --就是字面意思,log下来没有使用索引的query
?log=mylog.log --对所有执行语句进行记录

日志的存放:默认情况下,当开启时,所有的日志都存放在DataDir目录下. 如果没有指定名称的话,它会以后主机名为名称. 如主机名为songcomputer,则相关就的日志为songcomputer.log文件.Mysql日志的关闭与开启:使用以下命令查看是否启用了日志 :mysql>show variables like 'log_%’; 


凡Value值为OFF的表示未开启服务,若要开启只需要将上的my.ini配置信息写入(my.ini为mysql安装目录下),然后去掉前面的“#” 号,再重启mysql服务。

OK,现在会看到指定的日志文件已创建。相反地,若要停止mysql日志服务,只需要将my.ini中对应的配置信息去掉即 可。 >>>>相应的使用慢日志查询 手动的去读取慢日志以及修改慢日志的时间 show variables like 'long%' 会得到慢日志的时间 进行设置慢日志的值 set long_query_time =2 侧重的二进制文件二进制日志:从概述中我可以看到my.ini配置信息的log-bin没有指定文件扩展名,这是因为即使你指定上扩展名它也不使用。当mysql创建二进制日志文件 时,首先创建一个以“mysql_log_bin”为名称,以“.index”为后缀的文件;

再创建一个以“mysql_log_bin”为名称,以 “.000001”为后缀的文件。当mysql服务重新启动一次以“.000001”为后缀的文件会增加一个,并且后缀名加1递增;如果日志长度超过了 max_binlog_size的上限(默认是1G)也会创建一个新的日志文件;

使用flush logs(mysql命令符)或者执行mysqladmin –u –p flush-logs(windows命令提示符)也会创建一个新的日志文件。 既然写入的都是二进制数据,用记事本打开文件是看不到正常数据的,那怎么查看呢? 使用BIN目录下mysqlbinlog命令,如:

Bin>mysqlbinlog d:/mysql_log/mysql_bin.000001
Bin>mysqlbinlog d:/mysql_log/mysql_bin.000002
Bin>mysqlbinlog d:/mysql_log/mysql_bin.000003
Bin>mysqlbinlog d:/mysql_log/mysql_bin.000004
Bin>mysqlbinlog d:/mysql_log/mysql_bin.000005

使用SQL语句也可查看mysql创建的二进制的文件目录:Mysql> show master logs; 查看当前二进制文件状态:mysql> show master status;  至于准确的看懂日志文件,还需要读者仔细阅读,深深体会,这里就不再奥述了!

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
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor