程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql日記轉動

mysql日記轉動

編輯:MySQL綜合教程

mysql日記轉動。本站提示廣大學習愛好者:(mysql日記轉動)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql日記轉動正文


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>&2
else
    echo "log file do not exist;"
    exit 1
fi
LOG=$1
DB_USER="log"
DB_PASS="log"                                                                                                      
# Others vars
DATE=`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.log
refresh ok
[root@linux ~]# ls /usr/local/mysql/ |grep mysql
mysql.log
mysql.log_1

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved