search
HomeDatabaseMysql TutorialMySQL日志文件_MySQL

MySQL日志文件_MySQL

Jun 01, 2016 pm 01:29 PM
informationdatabaseRecord

bitsCN.com

MySQL日志文件

 

一、

 

MySQL有不同类型的日志文件,从它们当中可以查询到MYSQL都做了什么,对于MYSQL的管理是不可或缺的。

 

1、错误日志(The error log):记录数据库启动、运行以及停止过程中错误信息;

 

--log-error=[file-name]用来指定错误日志存放的位置。

 

  如果没有指定[file-name],默认hostname.err做为文件名,默认存放在DATADIR目录中。

 

错误日志文件的格式:

 

时间  [错误级别]  错误信息

 

MySQL客户端可以通过下列方法来获取错误日志的详细位置:

 

1.      mysql> show variables like 'log_error';  

 

2.      +---------------+-------------------------------------------+  

 

3.      | Variable_name | Value                       |  

 

4.      +---------------+-------------------------------------------+  

 

5.      | log_error     | /usr/local/mysql/var/51ososdb.err |  

 

6.      +---------------+-------------------------------------------+  

 

7.      1 row in set (0.00 sec) 

 

通过命令show variables like 'log_error'; 可以得到log_error变量的值,即是错误日志文件的详细位置。

 

错误日志文件的记录级别:

 

错误日志有3个level:error、warning 和information。我使用的是mysql-5.1.51,安装在/usr/local/mysql下。

 

在/usr/local/mysql/include/my_sys.h中

 

#cat  my_sys.h你会发现下面的定义

 

enum  loglevel {

 

ERROR_LEVEL,                 //错误级别

 

WARNING_LEVEL,              //警告级别

 

INFORMATION_LEVEL          //信息级别

 

};

 

下面是一个错误日志样版:

 

2.错误信息样板

 

  080313 05:21:55 mysqld started

 

  080313 5:21:55 InnoDB: Started; log sequence number 0 43655

 

  080313 5:21:55 [Note] /usr/local/mysql/bin/mysqld: ready for connections.

 

  Version: '5.0.26-standard-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Edition - Standard (GPL)

 

  080313 5:24:13 [Note] /usr/local/mysql/bin/mysqld: Normal shutdown

 

  080313 5:24:13 InnoDB: Starting shutdown...

 

  080313 5:24:16 InnoDB: Shutdown completed; log sequence number 0 43655

 

  080313 5:24:16 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

 

  080313 05:24:16 mysqld ended

 

  080313 05:24:47 mysqld started

 

  080313 5:24:47 InnoDB: Started; log sequence number 0 43655

 

  080313 5:24:47 [Note] /usr/local/mysql/bin/mysqld: ready for connections.

 

Version: '5.0.26-standard-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Edition - Standard (GPL)

 

2、ISAM(索引顺序访问方法)操作日志(The isam log):记录所有对ISAM表的修改,该日志仅仅用于调试ISAM模式;

 

3、SQL执行日志(the query log):记录了客户端的连接以及所执行的SQL语句;

 

4、更新日志(the update log):记录了改变数据的语句,已经不建议使用,由二进制日志替代;

 

5、二进制日志(the binary log):记录了所有对数据库数据的修改语句;

 

6、超时日志(the slow log):记录所有执行时间超过最大SQL执行时间(long_query_time)或未使用索引的语句;

 

如果你是在用mysql的复制、备份功能,那么服务器还提供一个叫做relay log的日志文件;

 

二、

 

默认情况下所有日志文件会记录在MYSQL的数据目录下,你可以通过强制mysql去关闭并重新打开一个文件进行日志记录,系统会自动加后缀(如.00001),方式有在mysql环境下执行语句mysql>flush logs;或者通过mysqladmin管理程序执行#mysqladmin flush-logs或#mysqladmin refresh

 

这些日志的启动方式可以在mysql_safe方式启动数据库的时候,后面跟选项参数,也可以在配置文件里配置,推荐采用第二种方式,配置方法很简单。

 

我只配置了三种日志:

 

[mysqld]

log=/var/log/mysqld_common.log

log-error=/var/log/mysqld_err.log

log-bin=/var/log/mysqld_bin.bin

 

日志的查看很简单,大部分都是文本,直接用vim、less、more之类的工具看就可以了,值得说明的是二进制文件的查看:

 

1). 首先确定是否开启了二进制文件记录功能

mysql>show variables like 'log_bin';

 

2). 如果你想知道现在记录二进制数据的文件具体信息,你可以通过下列语句看到现在正在记录哪个文件,以及记录的当前位置:

mysql>show master status;

 

3). 查看二进制数据需要借助程序mysqlbinlog,看看它支持哪些选项,根据自己需要来使用。

mysql>mysqlbinlog /var/log/mysql/mysql-bin.000040;

 

4)查询某个时间范围的可以执行下列语句,如果记录很多可以将结果定向到一个文件里自己慢慢看:-) :

mysql>mysqlbinlog --start-datetime='2008-01-01 00:00:00' --stop-datetime='2008-08-08 00:00:00'  /var/log/mysql/mysql-bin.000040 > ./tmp.log

 

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
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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools