How to Read MySQL Binary Log Files (BinLog) with mysqlbinlog

February 25, 2011 at 9:36 am | Posted in mysql_replication | Leave a comment

 

Binary log file, which normally has name with the format host_name-bin.xxxxxx and store in /var/lib/mysql directory, could not be opened and read straight away as it’s in unreadable binary format. To read the binary logs in text format, we can make use of mysqlbinlog command, which also able to readrelay log files written by a slave server in a replication setup. Relay logs have the same format as binary log files.

 

To use mysqlbinlog utility is simple, simply use the following command syntax to invoke mysqlbinlog after login in as root (else you have to specify user name and password) to shell via SSH:

mysqlbinlog [options] log_file ...

So to read and display the contents of the binary log file named binlog.000001, use this command:

mysqlbinlog binlog.000001

The binary log files and its data are likely to be very huge, thus making it almost impossible to read anything on screen. However, you can pipe the output of mysqlbinlog into a file which can be open up for later browsing in text editor, by using the following command:

mysqlbinlog binlog.000001 > filename.txt

To reduce the amount of data retrieved from binary logs, there are several options that can be used to limit the data that is been returned. Among the useful ones are listed below:

–start-datetime=datetime

Start reading the binary log at the first event having a timestamp equal to or later than the datetime argument. The datetime value is relative to the local time zone on the machine where you run mysqlbinlog. The value should be in a format accepted for the DATETIME or TIMESTAMP data types . For example:

mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000001

–stop-datetime=datetime

Stop reading the binary log at the first event having a timestamp equal or posterior to the datetime argument. This option is useful for point-in-time recovery. See the description of the –start-datetime option for information about the datetime value.

–start-position=N

Start reading the binary log at the first event having a position equal to the N argument. This option applies to the first log file named on the command line.

–stop-position=N

Stop reading the binary log at the first event having a position equal or greater than the N argument. This option applies to the last log file named on the command line.

 

Ubuntu: How To Create an ISO Image from a CD or DVD

February 14, 2011 at 12:13 pm | Posted in basic, Ubuntu | Leave a comment

1. Insert the CD or DVD that you want to make an ISO image of.

2. Open a terminal window.

  1. Execute the following command:

cat /dev/scd0 > /home/iso/test.iso

where,

 

/dev/scd0 --> path of the dvd device

/home/iso/test.iso --> name of the iso file

Ubuntu: How to Mount and Unmount ISO Files

1. Open a terminal window.

  1. You will need to create a new directory for your ISO image. Execute the following command in your terminal window:

sudo mkdir /media/iso

  1. Now execute this command to mount the ISO image:

mount -o loop /home/shamanstears/Documents/test.iso /media/iso/

4. Type ls /media/iso in terminal for list the files from iso images.

script for ping the host

January 31, 2011 at 7:31 am | Posted in shell script | Leave a comment

#!/bin/bash
# Script for check ping packet

for myHost in $(cat ip.txt)
do
ping -c 4 $myHost>/dev/null;
count=$(echo $?)
if [ $count -eq 0 ]; then
echo “Host $myHost is UP”
else
echo “Host $myHost is DOWN”
fi
done

script for ping and write it to log,if down ur server only

January 31, 2011 at 7:28 am | Posted in shell script | Leave a comment

# ping a site if no response then email a message

site=”your ip”

logfile=”/home/hariprakash/pinglog”

pagefile=”/home/hariprakash/down”

pagesite=”your ip”

ping -c 2 $site > /dev/null

#if 100% packet loss – a bad ping

if [ $? -gt 0 ]

then echo bad ping to $site on `date` >>$logfile

#can we connect to the mail server or some other outside server?

ping -c 2 $pagesite

# if we can’t ping the outside, then record so

if [ $? -gt 0 ]

then echo bad ping to $pagesite on `date` >> $logfile

fi

# go ahead and email.. will get it sooner or later

#cat $pagefile |sendmail -t

# instead of sendmail, you could use mail

cat $pagefile | mail -s ” mail server “your ipdaddress” site is down” hari.prakash@tnq.co.in

else touch “$logfile”

fi

we need to add the below content to “down” file

hariprakash@test-server:~$ vim down

From: a_valid_email_address

TO: a_valid_email_address

Subject: URDOWN

We can not ping

your IP/name server..

just u use command

touch pinglog

Script for backup the file and append the status of the copy in to the file with date and time

January 31, 2011 at 7:24 am | Posted in shell script | Leave a comment

root@test-server:~# cat a.sh

rsync -r -v /root/known_hosts /testing | sed “s/$/, $(date)/” >>/home/hariprakash/ab.txt

 

 

sed “s/$/, $(date)/” ==> append the date and time to the file

 

OUTPUT LOG:

root@test-server:~# cat /home/hariprakash/ab.txt

 

 

sending incremental file list,Sat Jan 29 15:54:08 IST 2011

 

known_hosts,Sat Jan 29 15:54:08 IST 2011

 

,Sat Jan 29 15:54:08 IST 2011

 

sent 10685 bytes received 31 bytes 21432.00 bytes/sec,Sat Jan 29 15:54:08 IST 2011

 

total size is 10608 speedup is 0.99,Sat Jan 29 15:54:08 IST 2011

 

sending incremental file list,Sat Jan 29 15:54:25 IST 2011

 

known_hosts,Sat Jan 29 15:54:25 IST 2011

 

,Sat Jan 29 15:54:25 IST 2011

 

sent 10685 bytes received 31 bytes 21432.00 bytes/sec,Sat Jan 29 15:54:25 IST 2011

 

total size is 10608 speedup is 0.99,Sat Jan 29 15:54:25 IST 2011

apache2: apr_sockaddr_info_get failed for If you are getting this error when you try to start or restart apache

January 14, 2011 at 7:09 am | Posted in apache, Error&solution | Leave a comment

apache2: apr_sockaddr_info_get failed for

If you are getting this error when you try to start or restart apache :

 

apache2: apr_sockaddr_info_get() failed for pirat9-desktop

apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

[ OK ]

 

 

The solution is the following :

 

Open apache2.conf file :

 

sudo vi /etc/apache2/apache2.conf

 

and add this line :

 

ServerName localhost

 

Save and exit

 

restart again

 

$ sudo /etc/init.d/apache2 restart

 

* Restarting web server apache2 … waiting [ OK ]

 

$

Uninstall / Delete / Remove Package

December 16, 2010 at 10:25 am | Posted in Ubuntu | Leave a comment

Just use the following syntax:
sudo apt-get remove {package-name}

For example remove package called xinetd, enter:
$ sudo apt-get remove xinetd

Remove package called xinetd along with all configuration files, enter:
$ sudo apt-get --purge remove xinetd

To list all installed package, enter:\
dpkg --list
dpkg --list | less
dpkg --list | grep -i 'http'

Fixing MySQL Replication with duplicate key error

December 15, 2010 at 9:24 am | Posted in mysql_replication, Ubuntu | Leave a comment


Today our MySQL Master tracking db went down (due to host server crashing) which consequently screwed up the slave. Here are the steps I took to fix it.
Firstly, check the slave status with:

 show slave status\G;

If the slave is reporting something like ”Last_Error: Error Duplicate entry replication”, this can be fixed by the following:

 stop slave;
 set global sql_slave_skip_counter=1;(IT AVOID ONE ERROR)
 start slave;
 show slave status\G;

It will take some time after issuing those commands for the slave to rebuild itself from the master, but you can check the progress by querying the db to see what record we are up to, for example:

 connect trackdb;
 SELECT * FROM `track` WHERE 1 ORDER BY id DESC LIMIT 10;

How To configure MySQL Replication

December 15, 2010 at 8:59 am | Posted in mysql_replication, Ubuntu | 2 Comments


a) You must have 2 servers(primery/secondary) running MySQL
b) There will be 2 configurations one for primery and another one for secondary.

$$$$$$$$$$$$$     Primery Server(  Master Side)  $$$$$$$$$$$$$

1) Edit /etc/hosts.allow and add this line ( you MUST change this IP’s for yours !! )

Mysql : 10.0.0.1

2) Edit   /etc/mysql/my.cnf or /etc/my.cnf

$$$$$$$$$$$$$$$ Comment this below lines $$$$$$$$$$$$$$$$
bind-address = xxx.xxx.xxx.xxx
skip-networking
####### Make sure this lines exists in the [mysqld] Section:
log-bin=mysql-bin

binlog-do-db=database1

binlog-do-db=database2

etc.,
server-id = 1

3) Now lets move to mysql using a power user like root xD

mysql> GRANT ALL ON databasename.* TO repl@'%' IDENTIFIED BY 'put_some_pass_here';
mysql> FLUSH PRIVILEGES;
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@'%' IDENTIFIED BY 'put_some_pass_here';

4) restart MySQL service

$$$$$$$$$$$$$$$$   Client Side $$$$$$$$$$$$$$


5) Edit my.cnf …. In my case located at: /etc/my.cnf
* I’m going to show just a what you need the my.cnf file contains much more info.

#### Add this lines or modify them
log-bin=SOME_NAME-relay-bin
server-id = 2
#### This number increases when you add more than one SLAVE os CLIENT to the MASTER server
master-host = 192.168.50.8
#### Put the Hostname or IP from your MASTER server
master-user = repl
master-password = put_some_pass_here
replicate-do-db=databasename1

replicate-do-db=databasename2

save and close the file.

you have to run this query to set the SLAVE. Before execute the query. you have to check  the MASTER_LOG_FILE and MASTER_LOG_POS in master log(mysql> show master status\G)of primary server

mysql -u root -p

mysql> CHANGE MASTER TO MASTER_HOST=’Ip_of_your_master’, MASTER_USER=’repl’, MASTER_PASSWORD=’some_password’, MASTER_LOG_FILE=’mysql-bin.000001′, MASTER_LOG_POS=345;

6) restart the service

7) done !! all data will be Replicated.

Troubleshooting:
Master:


mysql> SHOW GRANTS FOR repl;
mysql> SHOW MASTER LOGS \G
mysql> SHOW BINARY LOGS;
mysql> SHOW MASTER STATUS;
mysql> RESET MASTER   ==> CAUTON !!!

mysql> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000002

Position: 106

Binlog_Do_DB: opt

Binlog_Ignore_DB:

1 row in set (0.00 sec)

mysql> show processlist;

+-----+------------+------------------+------+-------------+------+----------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+-----+------------+------------------+------+-------------+------+----------------------------------------------------------------+------------------+

| 242 | root | localhost | NULL | Query | 0 | NULL | show processlist |

| 244 | slave_user | 10.0.9.242:37546 | NULL | Binlog Dump | 250 | Has sent all binlog to slave; waiting for binlog to be updated | NULL |

+-----+------------+------------------+------+-------------+------+----------------------------------------------------------------+------------------+

2 rows in set (0.00 sec)

SLAVE:


mysql> SHOW SLAVE STATUS;
mysql> STOP SLAVE;
mysql> START SLAVE;
mysql> RESET SLAVE; ==> CAUTON !!!

mysql> show processlist;

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+

| 46 | root | localhost | NULL | Query | 0 | NULL | show processlist |

| 47 | system user | | NULL | Connect | 276 | Waiting for master to send event | NULL |

| 48 | system user | | NULL | Connect | 270 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+

3 rows in set (0.02 sec)

---------------------------------------------

mysql> show slave status\G

or SHOW SLAVE STATUS;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 10.0.9.251

Master_User: slave_user

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 106

Relay_Log_File: tnqt111-relay-bin.000004

Relay_Log_Pos: 251

Relay_Master_Log_File: mysql-bin.000002

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: opt

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 106

Relay_Log_Space: 553

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

1 row in set (0.01 sec)

#######You can load the data(tables,data,etc., from databases),while u use the below command

Error1 :

mysql> LOAD DATA FROM MASTER;
ERROR 1219 (HY000): Error running query on master: Access denied; you need the RELOAD privilege for this operation
////////// IF YOU SEE THIS in SLAVE side .... Type This NEXT in the MASTER SERVER:

mysql> GRANT RELOAD on *.* to repl@'%' identified by 'your_password';
OR
mysql> GRANT SUPER on *.* to repl@'%' identified by 'your_password';

Error2:

mysql>load data from master;

While u will use the above command,u may got below error:

Error 1189 (08S01): Net error reading from master

Discussion Discussion

This error can happen while executing the LOAD DATA FROM MASTER statement because of a couple of reasons. It could happen if a non-MyISAM table was loaded. LOAD DATA FROM MASTER works only with MyISAM engine. It can also happen if a recoverable network error occurs. This error can happen while executing the LOAD DATA FROM MASTER statement because of a couple of reasons. It could happen if a non-MyISAM table was loaded. LOAD DATA FROM MASTER works only with MyISAM engine. It can also happen if a recoverable network error occurs.

Solution

If this error is thrown, make sure all tables on the master are MyISAM. If so, retry running the SQL statement. In case of databases containing InnoDB tables or other engines, use mysqldump for slave initialization. If this error is thrown, make sure all tables on the master are MyISAM. If so, retry running the SQL statement. In case of databases containing InnoDB tables or other engines, use mysqldump for slave initialization.

Change eth1 to eth0

December 13, 2010 at 11:33 am | Posted in network, Ubuntu | Leave a comment

We need to edit from NAME="eth1" to "eth0" in this file:

vim /etc/udev/rules.d/70-persitent-net.rules

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:0c:29:bf:c8:1b", ATTR{type}=="1", KERNEL=="eth*",
NAME="eth1"

To

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:0c:29:bf:c8:1b", ATTR{type}=="1", KERNEL=="eth*",
NAME="eth0"

Also we need to edit change the eth1 to eth0 in
the /etc/network/interfaces
and reboot the server.
After that eth0 is enabled

Next Page »

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.