Mysql Log scrolling

Source: Internet
Author: User

1. view log information
Copy codeThe Code is as follows:
Mysql> show global variables like '% log % ';
+ --------------------------------- +
| Variable_name | Value |
+ --------------------------------- +
| Back_log | 50 |
| Bin log_cache_size | 32768 |
| Binlog_format | MIXED |
| Expire_logs_days | 0 |
| General_log | ON |
| General_log_file |/usr/local/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)

There are three main log files above, mysql. log, mysqd. log, mysql-slow.log, except mysqld. logs cannot be refreshed by mysqladmin flush-logs. Other logs can be refreshed by mysqld. log is generated by the server startup program mysqld.

2. Generate a log to refresh the user
Copy codeThe Code is as follows:
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)

Log in with the root account and add a log user. Separate them clearly.

3. The log rolling script keeps logs for only one week.
Copy codeThe Code is as follows:
[Root @ linux ~] # Vim log. sh // Add the following content
#! /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
Add executable permission chmod + x log. sh

The script is simple, but it should be explained that mv $ {LOG }$ {LOG }_$ {DATE} will generate seven files in the first week, and the second week will overwrite the files in the last week, monday covers Monday and Tuesday.

4. Log scrolling
Copy codeThe Code is as follows:
[Root @ linux ~] #./Log. sh/usr/local/mysql. log
Refresh OK
[Root @ linux ~] # Ls/usr/local/mysql/| grep mysql
Mysql. log
Mysql. log_1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.