Home Database Mysql Tutorial mysql初识之日志文件篇_MySQL

mysql初识之日志文件篇_MySQL

Jun 01, 2016 pm 01:31 PM
mysql Record details

bitsCN.com

mysql初识之日志文件篇

 

日志文件

 

1. err日志

 

    error log 记录mysql在运行的过程中所有较为严重的警告和错误信息,以及mysql server每次启动和关闭的详细信息。系统在默认情况下关闭error log 功能。error log 默认存放在data目录下,默认文件名为主机名.err。error log 通过两种方式开启:

 

1). 启动mysqld时,附加上--log-error参数

 

2) . 在my.cnf中配置log-error系统环境变量

 

当进入mysql后执行 flush logs命令后,mysql会将当前的错误日志文件附加-old文件保存,并且创建一个新的空错误日志文件,仅仅在指定--log-error的情况下。

 

注:error log 不全是保存是警告和错误信息,还保存每次启动和关闭的信息。

 

ps启动时信息:130420 16:19:29 mysqld_safe mysqld from pid file /data0/mysql_data_7706/FZTEST-24178.pid ended130420 16:19:30 mysqld_safe Starting mysqld daemon with databases from /data0/mysql_data_7706error: Found option without preceding group in config file: /data0/mysql_data_7706/my.cnf at line: 1Fatal error in defaults handling. Program aborted130420 16:19:30 [Note] Plugin 'FEDERATED' is disabled.130420 16:19:30 [Note] Plugin 'ndbcluster' is disabled.130420 16:19:30  InnoDB: Initializing buffer pool, size = 8.0M130420 16:19:30  InnoDB: Completed initialization of buffer pool(以下省略) 查看error 日志是否启动:mysql> show variables like 'log_error';+---------------+---------------------+| Variable_name | Value                        |+---------------+---------------------+| log_error          | /var/log/mysqld.log |+---------------+---------------------+1 row in set (0.00 sec)关闭mysql:  mysqladmin -uroot -p shutdown 
Copy after login

2. 二进制日志(binlog)

binlog日志主要记录mysql的更新内容,记录每一条更新语句的执行的时间、消耗的资源,以及相关的事务信息。可以用于实时备份,与master/slave复制。

如何打开:

my.cnf中[mysqld] 节点上添加

查看binlog是否打开

mysql> show variables  like 'log_%';+---------------------------------+-----------------+| Variable_name                   | Value           |+---------------------------------+-----------------+| log_bin                             | ON              |查看binlog内容: /usr/local/mysql3306/bin/mysqlbinlog mysql-bin.00002log-bin-index文件作用:记录目录所有binlog文件[root@FZTEST-24178 mysql_data_7706]# cat mysql_7706-relay-bin.index./mysql_7706-relay-bin.000032binlog格式说明:[root@localhost ~]# mysqlbinlog  /home/mysql/binlog/binlog.000003  | more/*!40019 SET @@session.max_insert_delayed_threads=0*/;/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 4#120330 16:51:46 server id 1  end_log_pos 98    Start: binlog v 4, server v 5.0.45-log created 120330 16:51:46# Warning: this binlog was not closed properly. Most probably mysqld crashed writing it.# at 196#120330 17:54:15 server id 1  end_log_pos 294   Query   thread_id=3     exec_time=2     error_code=0SET TIMESTAMP=1333101255/*!*/;insert into tt7 select * from tt7/*!*/;# at 294#120330 17:54:46 server id 1  end_log_pos 388   Query   thread_id=3     exec_time=28    error_code=0SET TIMESTAMP=1333101286/*!*/;alter table tt7 engine=innodb/*!*/;
Copy after login

 

 

解析binlog格式

位置

位于文件中的位置,“at 196”说明“事件”的起点,是以第196字节开始;“end_log_pos 294”说明以第294字节结束

 

时间戳

事件发生的时间戳:“120330 17:54:46”

 

事件执行时间

事件执行花费的时间:"exec_time=28"

 

错误码

错误码为:“error_code=0”

 

服务器的标识

服务器的标识id:“server id 1”

 

其他参数说明:

1). binlog_do_db:表示记录指定数据库的二进制日志

2).binlog_ignore_db:表示忽略指定的数据库的二进制日志

3).  max_binlog_cache_size:表示使用binlog时最大的内存值

4). binlog_cache_size

此参数表示binlog使用的内存大小,可以通过状态变量binlog_cache_use和binlog_cache_disk_use来帮助测试。

       binlog_cache_use:使用二进制日志缓存的事务数量

       binlog_cache_disk_use:使用二进制日志缓存但超过binlog_cache_size值并使用临时文件来保存事务中的语句的事务数量

5).max_binlog_size

Binlog最大值,最大和默认值是1GB,该设置并不能严格控制Binlog的大小,尤其是Binlog比较靠近最大值而又遇到一个比较大事务时,为了保证事务的完整性,不可能做切换日志的动作,只能将该事务的所有SQL都记录进当前日志,直到事务结束

6).sync_binlog

这个参数直接影响mysql的性能和完整性

sync_binlog=0:

当事务提交后,Mysql仅仅是将binlog_cache中的数据写入Binlog文件,但不执行fsync之类的磁盘        同步指令通知文件系统将缓存刷新到磁盘,而让Filesystem自行决定什么时候来做同步,这个是性能最好的。

sync_binlog=n,在进行n次事务提交以后,Mysql将执行一次fsync之类的磁盘同步指令,同志文件系统将Binlog文件缓存刷新到磁盘。

Mysql中默认的设置是sync_binlog=0,即不作任何强制性的磁盘刷新指令,这时性能是最好的,但风险也是最大的。一旦系统绷Crash,在文件系统缓存中的所有Binlog信息都会丢失。

 

查询日志

 

查询日志即记录所有的查询语句的日志,一般建议不开启,有些query语句比较大,开启后对性能的也有较大的影响。一般用于跟踪某特殊 的性能问题才会短暂打开功能,默认的查询日志文件名为主机名.log。

 

慢查询日志

 

慢查询日志记录的是查询需要较长时间的query,通过在[mysqld] 下添加log-slow-queries=/tmp/slow_log 打开些功能,默认文件名是hostname-slow.log默认的目录是数据目录。

分析慢查询的工具有:msyqlslowdump、mysqlsla

 

innodb在线日志redo日志

 

innodb是一个事务安全的存储引擎,其事务安全性主要是通过在线redo日志和记录在表空间中的undo信息来保证redo日志中记录了innodb所做的所有物理变更和事务信息,通过redo日志和undo信息,innodb保证了在任何情况下的事务安全性。innodb的redo日志同样默认存放 在数据目录下,可通过innodb_log_group_home_dir来更改设置日志的存放公交车,通过innodb_log_files_in_group 设置日志的数量。

 

bitsCN.com
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Monitor Redis Droplet with Redis Exporter Service Monitor Redis Droplet with Redis Exporter Service Apr 10, 2025 pm 01:36 PM

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

See all articles