Home Database Mysql Tutorial mysql数据库数据变化实时监控

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

May 15, 2018 pm 04:50 PM
mysql warning Variety real time data database monitor

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
Copy after login

对于二次开发来说,很大一部分就找找文件和找数据库的变化情况 对于数据库变化。还没有发现比较好用的监控数据库变化监控软件。 今天,我就给大家介绍一个如何使用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
Copy after login
在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 --对所有执行语句进行记录
Copy after login

日志的存放:默认情况下,当开启时,所有的日志都存放在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
Copy after login

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

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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

See all articles