mysql日志滚动

2023年 4月 23日 28.1k 0

1,查看log情况 复制代码 代码如下: mysql show global variables like '%log%'; +---------------------------------+---------------------------------+ | Variable_name | Value | +---------------------------------+--------------------

1,查看log情况复制代码 代码如下:mysql> show global variables like '%log%';+---------------------------------+---------------------------------+| Variable_name                   | Value                           |+---------------------------------+---------------------------------+| back_log                        | 50                              || binlog_cache_size               | 32768                           || binlog_format                   | MIXED                           || expire_logs_days                | 0                               || general_log                     | ON                              || general_log_file                | /usr/local/mysql/mysql.log      || log                             | ON                              || log_bin                         | ON                              || log_bin_trust_function_creators | OFF                             || log_bin_trust_routine_creators  | OFF                             || log_error                       | /var/log/mysqld.log             || log_output                      | FILE                            || log_queries_not_using_indexes   | OFF                             || log_slave_updates               | OFF                             || log_slow_queries                | ON                              || log_warnings                    | 1                               || max_binlog_cache_size           | 4294963200                      || max_binlog_size                 | 1073741824                      || max_relay_log_size              | 0                               || relay_log                       |                                 || relay_log_index                 |                                 || relay_log_info_file             | relay-log.info                  || relay_log_purge                 | ON                              || relay_log_space_limit           | 0                               || slow_query_log                  | ON                              || slow_query_log_file             | /usr/local/mysql/mysql-slow.log || sql_log_bin                     | ON                              || sql_log_off                     | OFF                             || sql_log_update                  | ON                              || sync_binlog                     | 0                               |+---------------------------------+---------------------------------+30 rows in set (0.00 sec)上面主要有三个日志文件,mysql.log,mysqd.log,mysql-slow.log,除了mysqld.log不能通过mysqladmin flush-logs来刷新日志外,其他的都可以,mysqld.log是服务器启动程序mysqld产生的。

2,生成日志刷新用户复制代码 代码如下:mysql> GRANT RELOAD ON *.* TO 'log'@'localhost' IDENTIFIED BY 'log';Query OK, 0 rows affected (0.07 sec)mysql> flush privileges;Query OK, 0 rows affected (0.03 sec)用root账户登录进去,添加一个log的用户。分开清楚一点。

3,日志滚动脚本,只保留一个星期的日志复制代码 代码如下:[root@linux ~]# vim log.sh   //添加以下内容#!/bin/sh# log refresh if [ -f $1 ];then    echo "refresh ok" 1>&2else    echo "log file do not exist;"    exit 1fiLOG=$1DB_USER="log"DB_PASS="log"                                                                                                       # Others varsDATE=`date +%w`                                        BIN_DIR="/usr/local/mysql/bin"mv ${LOG} ${LOG}_${DATE}${BIN_DIR}/mysqladmin  -ulog -plog flush-logs添加可执行权限chmod +x log.sh

脚本很简单,不过有一点要解释一下,就是mv ${LOG} ${LOG}_${DATE},第一周会产生7个文件,第二周会覆盖上周的,星期一覆盖星期一,星期二覆盖星期二,以此内推。

4,日志滚动复制代码 代码如下:[root@linux ~]# ./log.sh /usr/local/mysql/mysql.logrefresh ok[root@linux ~]# ls /usr/local/mysql/ |grep mysqlmysql.logmysql.log_1

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论