Kunaljain's Weblog

February 10, 2009

Removing RPM packages

Filed under: Linux Tips & Tricks,MySql — Kunal Jain @ 04:14
Tags: ,

Try to remove MySQL from my server which my datacenter guys installed it along with the OS and while doing that i got the following error

shell> rpm -aq | grep mysql | xargs rpm -e

error: “mysql-devel-5.0.45-7.el5” specifies multiple packages
error: “mysql-5.0.45-7.el5” specifies multiple packages
error: “mysql-devel-5.0.45-7.el5” specifies multiple packages
error: “mysql-5.0.45-7.el5” specifies multiple packages

Then i google about this error and with some help from google and rpm manual i use the following command to remove MySQL from my server

shell > rpm -aq | grep mysql | xargs rpm -e --nodeps --allmatches

January 9, 2009

ERROR: 1062 Duplicate entry ‘localhost-‘ for key ‘PRIMARY’

Filed under: MySql — Kunal Jain @ 11:47
Tags: ,

If MySQL give this error then check your hostname

shell> hostname

It might be localhost. Change your hostname. To know how to change hostname click here

February 26, 2008

Automated backup script for Mysql

Filed under: MySql — Kunal Jain @ 17:41
Tags: , , ,

Open a file backup.sh and add the following lines in the file. Change UserName and Password with actual Username and Password.

/usr/local/mysql/bin/mysqldump --user=UserName --password=Password --lock-all-tables --all-databases | gzip > /home/user/backup/mysql/backup.sql.gz
cd /home/user/backup/mysql/
CURR=`date +%Y%m%d`
mv backup.sql.gz archives/backup.sql.gz.$CURR

This script create the file in archives folder in a gzip format.

October 29, 2007

Implementing Replication

Filed under: MySql — Kunal Jain @ 16:47

There are only few steps to implement replication. The first step is to set up a user account to use only for replication


In this sql statement the user account repluser is granted only what need for replication the host name is the HostName or IP Address of Slave Server. You can enter the statement on the slave server but with the Master HostName or IP Address.

****Configuring The Master Serve****

Open the file my.cnf which is usually located in /etc/my.cnf and add the following lines to the configuration file

log-bin = <path for Log_File>

binlog-do-db = db_test

server-id = 1

****db_test is the name of the Database we replicate on slave server

****Restart MySql

/etc/init.d/mysql restart

****Now on MySql shell check the Master Status


****SHOW MASTER STATUS shows output like

*************************** 1. row ***************************
File: log-bin.000002
Position: 79
Binlog_Do_DB: db_test
1 row in set (0.00 sec)


****Take the backup of your DataBase. On the shell prompt type

#mysql[data-dir]/bin/mysqldump -u <UserName> -p<Password> <Database Name> > backup.sql

and copy the backup.sql to the slave server with the following command

#scp backup.sql slave@hostname:~/backupfiles/

with this command backup.sql file is copied to backupfiles folder on slave server

****Configuring the slave server

After creating the user for replication as said above create the database in which you load the backup file of the master serve so we firstly create the database. On MySql prompt type

mysql>create database db_test

****Remember First db_test is on the Master Server and here we created a new Database. You can give it any name Same name helps in remembering which database is replicating.

mysql>show databases;

show you the list of all the databases.


Now on shell prompt open my.cnf file and add the following changes

server-id = 2

save the file and load the database of Master Server in the newly created Database on slave server with the help of following command

#mysql[data-dir]/bin/mysql -u <UserName> -p<password> <Database Name> < path to backup.sql file

****In this command Database Name is db_test which we created on slave server

****Now execute the following statement on the slave servers with the actual values

mysql> CHANGE MASTER TO MASTER_HOST = 'Master_HostName/IP Address',
-> MASTER_USER = 'Replicant UserName',
-> MASTER_PASSWORD = 'Password',
-> MASTER_LOG_FILE = 'Master Log File Name' ,
->  MASTER_LOG_POS = 'Master Log  Position';

NOTE:- Master_HostName -> is the Master Server IP Address or HostName

Master_user -> Replicant User Name which is repluser in my case

Master_password -> Password of the replicant user(repluser) which is password in my case

Master_Log_File -> show master status command gives you the Log File name

Master_Log_Pos -> show master status command gives you the Log Position

Now Restart your Mysql

#/etc/init.d/mysql restart

and also start slave by typing the following command on mysql prompt


****You can check the status of slave server by typing the following command on slave server

mysql> show slave status;

If this configuration doesn’t work then add the followling lines in my.cnf file on slave server with actual values

server-id = 2


master-user = repluser

master-password = password

master-connect-retry = 100

replicate-do-db = db_test

log-bin = /var/log/mysql/lob-bin.log

log-bin-index = /var/log/mysql/log-bin.index

log-error = /var/log/mysql/log-error.log

relay-log = /var/log/mysql/relay-log.log

relay-log-info-file = /var/log/mysql/relay-log.info

relay-log-index = /var/log/mysql/relay-log.index

****Now again restart your Mysql and also slave Server the check the salve status by issued the show slave status command

October 9, 2007

Installing Mysql on Linux

Filed under: MySql — Kunal Jain @ 09:27

Installing Mysql

# groupadd mysql
# useradd -g mysql mysql
# cd /usr/local
/usr/local# gunzip <PATH_TO_MYSQL-VERSION.tar.gz> | tar xvf -
/usr/local# ln -s FULL_PATH_TO_MYSQL-VERSION mysql
/usr/local# cd mysql
/usr/local/mysql# scripts/mysql_install_db --user=mysql
/usr/local/mysql# chown -R root
/usr/local/mysql# chown -R mysql data
/usr/local/mysql# chgrp -R mysql
#/usr/local/mysql/bin/mysqld_safe --user=mysql &

Note:- To Run MySql if shut down then


and press enter MySql starts working

Blog at WordPress.com.