Posts

Showing posts from July, 2009

AWK: Pattern Matching and Processing

awk 'pattern {action}' filename Reads one line at a time from file, checks for pattern match, performs action if pattern matched pattern. NR is a special awk variable meaning the line number of the current record can use a line number, to select a specific line, by comparing it to NR (for example: NR == 2) can specify a range of line numbers (for example: NR == 2, NR == 4) can specify a regular expression, to select all lines that match $n are special awk variables, meaning the value of the nth field (field delimiter is space or tab) $0 is the entire record can use field values, by comparing to $n (for example: $3 == 65) every line is selected if no pattern is specified Instructions print - print line(s) that match the pattern, or print fields within matching lines print is default if no action is specified there are many, many instruction, including just about all C statements with similar syntax other instructions will be covered in future courses examples, using the fi

MySQL Replication : Purged binary logs

Yesterday I have found that there is no space left on server of MySQL master and on Slave. Once I debugged I have come to know that there is GB's of bin-log files on Master and relay-log on Slave. Its due to I have forget to add a expire_logs_days Variable in my.cnf during the configuration of replication server. # expire_logs_days = 7 It will purged binary logs older than 7 days.The old logs will be purged during the next bin-log switch. Or, You can also delete bin-log manually using command : PURGE BINARY LOGS TO 'mysql-bin.010'; PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

MYSQL: slow queries log

MySQL has built-in functionality that allows you to log SQL queries to a file , You can enable the full SQL queries logs to a file or only slow running queries log. It is easy for us to troubleshoot/ debug the sql statement if SQL queries log enable , The slow query log is used to find queries that take a long time to execute and are therefore candidates for optimization. To enable you just need to add some lines to your my.cnf file, and restart. Add the following: * To enable slow Query Log only log-slow-queries = /var/log/mysql/mysql-slow.log long_query_time = 1 After enabling slow query, mysqld writes a statement to the slow query log file and it consists of all SQL statements that took more than long_query_time seconds to execute. The time to acquire the initial table locks is not counted as execution time. mysqld only log after SQL statements has been executed and after all locks have been released, so log order might be different from execution order. The minimum and defau