MySQL log files   (1)

MySQL has several log files that can help you find out what activity is taking place.

log type     
information write to log file

error log  Problems encoutered  starting, running or stopping mysqld
General query  log      Established client connections and statements receive from client
Binary log Statements that change data(also are used to replicate)

Slow query

DDL log(metadata log)


Queries that take more seconds to execute

Metadata operations performanced by DDL statements

By default MySQL sever‘s log files store in the data directory. You can force the server to close or reopen the log files.

When using MySQL with logging enabled, you may want to back up and remove old log file from time to time, and tell MySQL to start new logs to new log files.

On linux installation, you can use the mysql-log-rotate script for this. If you installed MySQL from RPM distribution, this script should have been installed automatically. Be carefull with this script if you are using binary log for replication. You should not remove binary log until you are certain that their contents have been processed by all slaves.

[[email protected] support-files]# pwd
/opt/mysql/support-files
[[email protected] support-files]# ls -ld mysql-log-rotate 
-rwxr-xr-x 1 root root 801 Feb 9 2015 mysql-log-rotate
[[email protected] support-files]# more mysql-log-rotate 
# This logname can be set in /etc/my.cnf
# by setting the variable "err-log"
# in the [safe_mysqld] section as follows:
#
# [safe_mysqld]
# err-log=/data/mysql/mysqld.log
#
# If the root user has a password you have to create a
# /root/.my.cnf configuration file with the following
# content:
#
# [mysqladmin]
# password = <secret> 
# user= root
#
# where "<secret>" is the password. 
#
# ATTENTION: This /root/.my.cnf should be readable ONLY
# for root !

/data/mysql/mysqld.log {
# create 600 mysql mysql
notifempty
daily
rotate 3
missingok
compress
postrotate
# just if mysqld is really running
if test -x /opt/mysql/bin/mysqladmin && /opt/mysql/bin/mysqladmin ping &>/dev/null
then
/opt/mysql/bin/mysqladmin flush-logs
fi
endscript
}

On orther system, you should install a short script yourself from cron for handling log files.

For binary log, you can set expire_logs_days system variable to expire binayr log automatically after given the number days.

mysql> show variables like ‘%expire%‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 0 |
+------------------+-------+
1 row in set (0.00 sec)

mysql> set global expire_logs_days=5;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like ‘%expire%‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 5 |
+------------------+-------+
1 row in set (0.00 sec)

If you just set expire_logs_days system variable in mysqld instance, it would be return the old value when you restart the MySQL server. In order to set expire_logs_days system varible permanetly, you can write the parameter in mysql server parameter file named my.cnf which locates at /etc/ or mysql_home/etc

vim /etc/my.cnf

[mysqld]

expire_logs_days=10

You can force MySQL to start using new log files by flushing the logs. Log flushing occurs when you issue a flush logs command or execute a mysqladmin flush-logs, mysqladmin refresh, mysqldump --fulsh-logs or mysqldump --master-data.

eg.

mysql> flush logs;Query OK, 0 rows affected (0.10 sec)
[[email protected] ~]# mysqladmin flush-logs -uroot -pEnter 
password: 
[[email protected] ~]# mysqladmin refresh -uroot -pEnter 
password:
时间: 2024-10-10 19:29:09

MySQL log files   (1)的相关文章

手动创建binary log files和手动编辑binary log index file会有什么影响

一.了解Binary Log结构 1.1.High-Level Binary Log Structure and Contents • Binlog包括binary log files和index file• 每个binary log文件的前4字节是Magic Number,紧接着是一组描述数据修改的Events • The magic number bytes are 0xfe 0x62 0x69 0x6e = 0xfe 'b''i''n' • 每个Event包括header bytes和da

调整innodb redo log files数目和大小的具体方法和步骤

相较于Oracle的在线调整redo日志的数目和大小,mysql这点则有所欠缺,即使目前的mysql80版本,也不能对innodb redo日志的数目和大小进行在线调整,下面仅就mysql调整innodb redo log files数目和大小的具体方法和步骤进行说明.1. 停止mysql服务器,并确信对其进行了正常关闭:2. 编辑my.cnf 文件以对其中的redo log file相关配置进行调整. 为了改变redo log file的大小,需对选项innodb_log_file_size进

Oracle log files Troubleshooting Oracle

Oracle log files The following Oracle log files are helpful for resolving issues with Oracle components: Table: Log files for Oracle RAC 10g Release 2 Table: Log files for Oracle RAC 11g Release 2 and later versions Table: Log files for Oracle databa

【oracle】oracledba14 archived log files

The loss of which two types of files may require a recovery with the RESETLOGS option?(Choose two.) A. control files B. password file C. archived log files D. system-critical data files for which all the redo entries are present E. non-system-critica

【改变mysql 日志位置Bug】Could not use mysql.log for logging (error 13)

今天手贱,看到mysql 的日志在/var/log/mysql下面.总是觉得别扭,于是就想改变日志的位置, 本人开发环境 vagrant  + ubuntu12.04 ,在/etc/mysql/mysql中修改了general_log的位置,放在/data/logs/mysql下面 然后重启服务,service mysql restart 查看错误日志发现说 /usr/sbin/mysqld: File '/data/logs/mysql/mysql.log' not found (Errcod

【oracle】oracledba15 To uniquely identify the archived log files for each incarnation of the databas

You are using Oracle Database 10g. The log LOG_ARCHIVE_FORMAT pa rameter is set to 'LOG%t_%_s_%r.dbf'. Why is %r used in the file name format? A. To uniquely identify the archived log files with the restore operation. B. To uniquely identify the arch

How to delete expired archive log files using rman?

he following commands will helpful to delete the expired archive log files using Oracle Recovery Manager(RMAN).Connect to the Rman prompt and try the bellow commands. RMAN>list expired archivelog all; RMAN>crosscheck archivelog all; RMAN>delete n

解决Cannot find MySQL header files under /usr/include/mysql的错误

按照下面的步骤能成功,亲测.转帖,做笔记 编译php-5.5-6的mysql支持,出现Cannot find MySQL header files under /usr/include/mysql. Note that the MySQL client library is not bundled anymore!错误!解决方法如下: [[email protected] php-5.5.6]# ./configure --prefix=/usr/local/php --with-config-

编译安装php时提示Cannot find MySQL header files的解决方法

php的配置文件中有一行--with-mysql=/usr/local/mysql ,安装的时候提示:configure: error: Cannot find MySQL header files under yes.Note that the MySQL client library is not bundled anymore. 这是由于安装mysql时没有安装mysql头文件,或者是路径指定不正确,php找不到mysql的头文件引起的错误提示. 解决方法.1. 查看你的系统有没有安装my