1, view log situation
Copy Code code as follows:
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 |
+---------------------------------+---------------------------------+
Rows in Set (0.00 sec)
There are mainly three log files above, Mysql.log,mysqd.log,mysql-slow.log, in addition to Mysqld.log can not be mysqladmin flush-logs to refresh the log, the other can, Mysqld.log is generated by the server startup program mysqld.
2, generate log Refresh user
Copy Code code 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 a little bit more clearly.
3, log scrolling script, keep only one weeks of log
Copy Code code as follows:
[Root@linux ~]# Vim log.sh//Add the following
#!/bin/sh
# Log Refresh
If [F $];
Then
echo "Refresh OK" 1>&2
Else
echo "Log file does 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 permissions chmod +x log.sh
The script is simple, but one thing to explain is that MV ${log} ${log}_${date, the first week will produce 7 files, the second week will cover last week, Monday cover Monday, Tuesday cover Tuesday, in order to push.
4, log scrolling
Copy Code code as follows:
[Root@linux ~]#./log.sh/usr/local/mysql/mysql.log
Refresh OK
[Root@linux ~]# ls/usr/local/mysql/|grep MySQL
Mysql.log
Mysql.log_1