Let's Share Knowledge And Make A Difference

  • Monitor your network and systems like a hawk

    There are some perfact open souce solution for monitoing your Network devices and server system's health. Nagios, Cacti, WhatsUpGold and Smokeping are the leading monitoring tools among them...

    Read More
  • Email service and Security

    Now a days life without email service is unthinkable and E-mail service is quite expensive. As always linux gives us the answer with a strong mail service named postfix...

    Read More
  • Data Center Solution

    A data centre is a facility where companies can keep and operate most of the ICT infrastructure that supports their business. IT host the most critical systems that are vital to the continuity of daily operations...

    Read More

Thursday, May 2, 2013

Basic Mysql configuration

Basic Mysql configuration

In Windows:
. Enable mysql from cmd:
System Properties > Advance > Environment Variables > (scroll down to) Path > Edit > ;E:\Program Files\xampp\mysql\bin (add this)

. create password for root user by using database location. open run > cmd. and login as root user,
. 1sr way:
~# mysqladmin -u root password "123456"
~# mysql -u root -p
~# sudo /etc/init.d/mysql restart

. 2nd way using mysqladmin
~# mysql -u root
~# UPDATE mysql.user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 2 rows affected (0.22 sec)
Rows matched: 2  Changed: 2  Warnings: 0

~# FLUSH PRIVILEGES;
~# mysql -u root -p
~# database

Here,
mysql.user = "user" table in "mysql" database
Password = "Password" collum in "mysql" database
User = 'root' > update all row value's which name is root
FLUSH PRIVILEGES = re-read the tables

. Creating users and setting their permissions:
~# CREATE USER web@localhost;
~# UPDATE mysql.user SET PASSWORD = PASSWORD('NEWPASSWORD') WHERE user = 'web';
~# GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER, CREATE TEMPORY TABLES, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON *.* TO web@localhost;
~# FLUSH PRIVILEGES;

~# CREATE USER admin@localhost;
~# UPDATE mysql.user SET PASSWORD = PASSWORD('290909') WHERE USER = 'admin';
OK, 1 row affected (0.00 sec)
atched: 1  Changed: 1  Warnings: 0
~# GRANT ALL ON *.* TO admin@localhost WITH GRANT OPTION;
~# FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

If you want to create a database and set up tables for the same use the following two sql commands:
1. CREATE DATABASE - create the database
2. CREATE TABLE - create the table
3. INSERT - To add/insert data to table

. Creating and Droping a database:
~# CREATE DATABASE sales;
~# SHOW DATABASE;
~# DROP DATABASE sales;
~# SHOW DATABASE;

. Creating database:
~# CREATE DATABASE test;

. Creating tables:
~# USE test;
~# CREATE TABLE test_customer (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
address VARCHAR(255),
city VARCHAR(255),
state CHAR(2),
zip CHAR(10),
email VARCHAR(20)
);

~# SHOW TABLES;
+----------------+
| test_customer  |
+----------------+
1 row in set (0.20 sec)

. Display the rules for the columns
~# DESRIBE test_customer;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| name    | varchar(255) | YES  |     | NULL    |                |
| address | varchar(255) | YES  |     | NULL    |                |
| city    | varchar(255) | YES  |     | NULL    |                |
| state   | char(2)      | YES  |     | NULL    |                |
| zip     | char(10)     | YES  |     | NULL    |                |
| email   | varchar(20)  | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
7 rows in set (0.30 sec)

. Now insert data to the table "test_customer"
~# INSERT INTO test_customer (id,name,address,city,state,zip,email) VALUES (1,"Md. Mahidul Hasan","Tolarbag","Dhaka","Mirpur-1","1216","mahidul24@gmail.com");
~# INSERT INTO test_customer (id,name,address,city,state,zip,email) VALUES (2,"Mrs. Maya Hasan","Tolarbag","Dhaka","Mirpur-1","1216","mahidul24@gmail.com");

. Display the table
~# SELECT * FROM test_customer;
+----+-------------------+----------+-------+-------+------+---------------------+
| id | name              | address  | city  | state | zip  | email               |
+----+-------------------+----------+-------+-------+------+---------------------+
|  1 | Md. Mahidul Hasan | Tolarbag | Dhaka | Mi    | 1216 | mahidul24@gmail.com |
|  2 | Mrs. Maya Hasan   | Tolarbag | Dhaka | Mi    | 1216 | mahidul24@gmail.com |
+----+-------------------+----------+-------+-------+------+---------------------+
2 rows in set (0.86 sec)

. Droping database:
~# DROP TABLE test_customer;
~# SHOW TABLES;

. Data type concept in mysql:
1. Numeric - for numbers
Integer: 1,2,3
  Floating point: 1.2312.., 2.123444...
Fixed point (after decimel): 1.24, 7.2

2. String - for words and text
Fixed: always should be fixed (two or three ... like state=) same size
Variable: diffrent values and sizes. Uses in name or address...
CHAR: for textual data
BINARY: for non-textual data. Fixed lenth.
VARBINARY: for non-textual data. Variable lenth.

3. Large storage - for documents and files
BLOB: binary large object for non-text data
Tinyblob - up to 256 bytes
blob - up to 64K bytes
  Mediumblob - up to 16M bytes
Longblob - up to 4G bytes

TEXT: for text type
Tinytext - up to 256 bytes
Text - up to 64K bytes
  Mediumtext - up to 16M bytes
Longtext - up to 4G bytes

4. Date and time
5. Bit values - for binary logical values and flags (declair with BIT). Like 11110000 means 240.
6. Enumeration - for mnemonic values





How to install and configure MailScanner, clamav and SpamAssassin using tar on Debian/Ubuntu

How to install and configure MailScanner, clamav and SpamAssassin using tar on Debian/Ubuntu

Remove MailScanner:
root@mail:root@mail:~# /etc/init.d/mailscanner stop
root@mail:root@mail:~# apt-get remove mailscanner

Install MailScanner Dependencies:
root@mail:root@mail:~# apt-get install libconvert-tnef-perl libdbd-sqlite3-perl libfilesys-df-perl libmailtools-perl libmime-tools-perl libmime-perl libnet-cidr-perl libsys-syslog-perl libio-stringy-perl libfile-temp-perl
root@mail:root@mail:~# apt-get install gcc g++ cpp zlib1g-dev libgmp3-dev perl bzip2 zip make patch automake libhtml-template-perl perl-suid
root@mail:root@mail:~# apt-get install linux-headers-`uname -r` build-essential libnewt-dev libusb-dev

Install clamav:
root@mail:root@mail:~# adduser clamav
root@mail:root@mail:~# http://downloads.sourceforge.net/clamav/clamav-0.97.3.tar.gz

However, because apt resource is backdated 0.94, it is better to download latest tarball. after installing, use the following commands:
root@mail:root@mail:~# tar -zxvf clamav-0.97.3.tar.gz
root@mail:root@mail:~# cd clamav-0.97.3
root@mail:root@mail:~# ./configure
root@mail:root@mail:~# make
root@mail:root@mail:~# make install

Run the following command to update the ClamAV if needed
root@mail:root@mail:~# freshclam –v

Configuring MailScanner:
root@mail:root@mail:~# wget http://www.mailscanner.info/files/4/tar/MailScanner-install-4.82.6-1.tar.gz
root@mail:root@mail:~# tar -zxvf MailScanner-install-4.82.6-1.tar.gz
root@mail:root@mail:~# cd MailScanner-install-4.82.6
root@mail:root@mail:~# ./install.sh

Backup and edit MailScanner.conf
root@mail:root@mail:~# cp /opt/MailScanner/etc/MailScanner.conf /opt/MailScanner/etc/MailScanner.conf.bak
root@mail:root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf

Set the following settings in /etc/MailScanner/MailScanner.conf  “or”

root@mail:root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
%org-name% = Bangladesh Online
%org-long-name% = Bangladesh Online
%web-site% = www.bol-online.com
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Virus Scanners = clamav
Spam List = SBL+XBL
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin

Tuning MailScanner:
root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
Virus Scanning = yes
Virus Scanners = clamav
Use SpamAssassin = yes
Ignore Spam Whitelist If Recipients Exceed = 50
Required SpamAssassin Score = 3
High SpamAssassin Score = 4
SpamAssassin Auto Whitelist = no
Spam Actions = deliver header "X-Spam-Status: Yes"
High Scoring Spam Actions = forward spam.bol@bol-online.com
Log Speed = no
Log Spam = yes
Log Non Spam = yes
Log Delivery And Non-Delivery = yes
Log Permitted Filenames = yes
Log Permitted Filetypes = yes
Log Permitted File MIME Types = yes
Log Silent Viruses = yes
Log Dangerous HTML Tags = yes
Log SpamAssassin Rule Actions = yes
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin

root@mail:root@mail:~# vim /opt/MailScanner/etc/filetype.rules.conf (type # beginning of the following lines)

     #deny   self-extract     No self-extracting archives            No self-extracting archives allowed
     #deny   executable       No executables                         No programs allowed
     #deny   ELF              No executables                         No programs allowed
     #deny   Registry         No Windows Registry entries            No Windows Registry files allowed

Then we will need to ensure that the user "postfix" can write to /var/spool/MailScanner/incoming and /var/spool/MailScanner/quarantine:

root@mail:root@mail:~# chown postfix.postfix /var/spool/MailScanner/incoming
root@mail:root@mail:~# chown postfix.postfix /var/spool/MailScanner/quarantine

SpamAssassin Configuration:
If you don't want to use spam assassign,
root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
Use SpamAssassin = no
                           
Postfix settings:
root@mail:root@mail:~# vim /etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks

Edir header_checks
root@mail:root@mail:~# vim /etc/postfix/header_checks

Add this line to the file, without it nothing will work:
/^Received:/ HOLD

Start MailScanner:
root@mail:root@mail:~# /opt/MailScanner/bin/check_mailscanner

Stop MailScanner:
root@mail:root@mail:~# pkill -9 MailScanner

“OR” Start the system as follows:
root@mail:root@mail:~# /etc/init.d/mailscanner start
root@mail:root@mail:~# /etc/init.d/postfix start

[Optional: Disable permission checks on MailScanner directories Comment out the lines that check directory permissions on /var/* in /etc/rc2.d/S20mailscanner]

Set MailScanner to start at boot ti.In the file /etc/default/mailscanner, make sure this is set to 1:
run_mailscanner=1

Install spamassassin:
root@mail:~# wget http://mirrors.ispros.com.bd/apache//spamassassin/source/Mail-SpamAssassin-3.3.2.tar.gz

Make directory for SpamAssassin and set permissions
root@mail:~# mkdir /var/spool/MailScanner/spamassassin
root@mail:~# chown postfix /var/spool/MailScanner/spamassassin

Reload mailq:
To see the que mail in postfix we use,
root@mail:~# mailq

To see the que mail in mailscanner we use,
root@mail:~# postqueue -p

Sometime mailscanner hangsup due to lots of mail que or low configuration server. To release this qued mail to the postfix mailq we use,
root@mail:~# postsuper -r ALL
root@mail:~# postsuper -h ALL


Log analyzers: Squint Configuration and Tuning

Squint Configuration and Tuning (tested 100% works)

Question:
1. how to install squint?
2. how to restart squint?
3. how to set schedule timer for update at squint?
4. how can we create user for squint?

Solution:
1. Squint Installation:
root@proxy:~# wget www.ledge.co.za/software/squint/squint-0.3.8.tar.gz
[root@mail ~]# tar -zxvf squint-0.3.8.tar.gz
squint-0.3.8/
squint-0.3.8/Makefile
squint-0.3.8/COPYING
squint-0.3.8/Changelog
squint-0.3.8/TODO
squint-0.3.8/fakenames
squint-0.3.8/INSTALL
squint-0.3.8/userlist
squint-0.3.8/squint.cron.sh
squint-0.3.8/squint.pl

root@proxy:~# cd /root/squint-0.3.8
root@proxy:~# cp squint.pl squint.cron.sh /usr/local/bin
root@proxy:~# squint.cron.sh init
root@proxy:~# squint.cron.sh all

2. Restart Squint:
root@proxy:~# squint.cron.sh all

3. Set the update schedule everyday at 1:30 PM from corn.d file like this way,
root@proxy:~# vim /etc/crontab
# m h dom mon dow user  command
# squint squid reports
# Weekly, on Mondays
00 01 * * *  root /usr/local/bin/squint.cron.sh weekly

# Monthly, on the first day of the month
00 02 1 * *    root /usr/local/bin/squint.cron.sh monthly

# Daily at 3am
57 12 * * *    root /usr/local/bin/squint.cron.sh daily

###squint###
#45 12 * * 7     root  /usr/local/bin/squint.cron.sh all

root@proxy:~# cd /usr/local/bin/
root@proxy:/usr/local/bin# chmod 777 squint.cron.sh
root@proxy:/usr/local/bin# chown root:root squint.cron.sh
root@proxy:~# /etc/init.d/cron restart

4. Create user for squint:
Just install the web server authentication.

5. Setup squint – to convert a squid log into a browsable HTML report:
Download actual version of squint and extract it:
    ~# wget http://www.ledge.co.za/software/squint/squint.tar.gz
    ~ tar xvf squint.tar.gz
    rm squint.tar.gz
    cd squint-0.3.18/
   
Mofidy BASEDIR, LOGDIR and HTTPDCONF in squint.cron.sh:
    ~# vi squint.cron.sh
    BASEDIR=”/var/www/localhost/htdocs/squint”
    LOGDIR=”/var/log/squid”
    HTTPDCONF=/etc/apache2/httpd.conf
   
Install squint:
    ~# make install

Create a place for the reports in /var/www/localhost/htdocs/squint and install a crontab entry to run the report daily, weekly and monthly:
    ~# make init

Verify if it is installed correctly:
    ~# ls -ald /var/www/localhost/htdocs/squint
    ~# less /etc/crontab
    ~# cd ..
    ~# rm -r squint*
Point your web-browser to http://proxyhost/squint to see the reports.

Log analysers: Sqstat configuration

Sqstat Configuration

Objectives:
1. Questions?
2. Concept
3. System requirements
4. Scenario
5. Configuration
6. Log files location
7. Troubleshooting
8. Reference
9. Real life-Script
10. Follow our vedio tutorial at the youtube link

Questions?
Q. What is Sqstat?
A: Sqstat is a web based real-time browsing Monitoring tool.

Q. Why we need it?
A. we need to monitor the current user's browsing logs (bandwidth, browsing site etc.) from the web server using web browser.

Q. How many packages are there like this?
A. There are many packages which genarete web log report but not in real-time report. At least I'm not aware of!!!

Concept
Sometimes we need to monitor the current browsing logs from the web server using web browser. Then one of our great solution is Sqstat. And trust me when I tell you this is a awsome package.

System requirements
. PHP (you need PHP 4.1.0 or newer) with installed pcre extension
. (optional) PHP session extension if you want to see current/average CPS
. Squid proxy server
. a web-browser

Scenario
Here my proxy server's ip address is 192.168.1.11 (10.0.0.1) and the local network is 10.0.0.0/24. And it is also transparent squid which listening on 8080 port. So, lets get start. And Don't afraid. Just walk with me, you will be smilling later.

Sqstat configuration
1. Sqstat is php package. So, we need to install php5 with apache2 to read it.
root@ns2:~# apt-get install apache2
root@ns2:~# apt-get install php5
root@ns2:~# apt-get install apache2-mpm-prefork
root@ns2:~# apt-get install libapache2-mod-php5
root@ns2:~# apt-get install apache2-mpm-worker

2. Install and configure squid. Here, we need to allow cachemgr protocol from localhost or from the server's ip address.
root@ns2:~# apt-get install squid
root@ns2:~# vim /etc/squid/squid.conf

# Squid normally listens to port 3128
http_port 8080 transparent

#Recommended minimum configuration:
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl mynetwork src 10.0.0.0/24
acl webserver src 192.168.1.11/255.255.255.255

# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access allow manager webserver
http_access deny manager

# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
http_access allow mynetwork

3. Firewall (iptables) configuration.
root@ns2:~# vim /etc/init.d/iptables

# Assigning our local network
our_network="10.0.0.0/24"

# Redirect http to SQUID.
iptables -t nat -A PREROUTING -p TCP -s "$our_network" --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p TCP --dport 8080 -j REDIRECT --to-port 8080

4. sqstat installation and configuration from tar file.
root@ns2:~# wget http://samm.kiev.ua/sqstat/sqstat-1.20.tar.gz
root@ns2:~# tar -zxvf sqstat-1.20.tar.gz
root@ns2:~# mv sqstat-1.20 /var/www/
root@ns2:~# cd /var/www/
root@ns2:/var/www# mv sqstat-1.20 sqstat
root@ns2:/var/www# mv config.inc.php.defaults config.inc.php
root@ns2:/var/www# vim /var/www/sqstat/config.inc.php

<?php
/* global settings */
$use_js=true; // use javascript for the HTML toolkits

//===================== Change the following settings =====================//
// Maximum URL length to display in URI table column
DEFINE("SQSTAT_SHOWLEN",100);

/* proxy settings */
/* Squid proxy server ip address or host name */
#$squidhost[0]="127.0.0.1";
$squidhost[0]="192.168.1.11";

/* Squid proxy server port */
#$squidport[0]=3128;
$squidport[0]=8080;
//========================================================================//

/* cachemgr_passwd in squid.conf. Leave blank to disable authorisation */
$cachemgr_passwd[0]="";
/* Resolve user IP addresses or print them as numbers only [true|false] */
$resolveip[0]=false;
/* uncomment next line if you want to use hosts-like file.
   See hosts.txt.dist. */
// $hosts_file[0]="hosts.txt"
/* Group users by hostname - "host" or by User - "username". Username work only
   with squid 2.6+ */
$group_by[0]="host";
/* you can specify more than one proxy in the configuration file, e.g.: */
// $squidhost[1]="192.168.0.2";
// $squidport[1]=3129;
// $cachemgr_passwd[1]="secret";
// $resolveip[1]=true;
// $hosts_file[1]="otherhosts.txt"

?>

5. restart the squid and the web server.
root@ns2:~# /etc/init.d/squid restart
root@ns2:~# /etc/init.d/apache2 restart

6. find the log reports.
root@ns2:~# tail -f /var/log/syslog

7. Now, open the firefox browser and hit the following link. Set the auto refresh time as per your requirements. Oh! please replace the ip 192.168.1.11 with your server's ip address.
http://192.168.1.11/sqstat/sqstat.php

Troubleshooting:
If you hit http://192.168.1.11/sqstat/sqstat.php and found your browser is tring to download the sqstat.php insted running the web page then run apt-get install apache2-mpm-prefork. First try it from another pc because sometimes browser hanged still if you close and reopen it.


Real life-Script:
root@ns2:~# apt-get install apache2
root@ns2:~# apt-get install php5
root@ns2:~# apt-get install apache2-mpm-prefork
root@ns2:~# apt-get install squid
root@ns2:~# vim /etc/squid/squid.conf

# Squid normally listens to port 3128
http_port 8080 transparent

#Recommended minimum configuration:
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl mynetwork src 10.0.0.0/24
acl webserver src 192.168.1.11/255.255.255.255

# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access allow manager webserver
http_access deny manager

# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
http_access allow mynetwork

root@ns2:~# vim /etc/init.d/iptables
# Assigning our local network
our_network="10.0.0.0/24"

# Redirect http to SQUID.
iptables -t nat -A PREROUTING -p TCP -s "$our_network" --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p TCP --dport 8080 -j REDIRECT --to-port 8080

root@ns2:~# wget http://samm.kiev.ua/sqstat/sqstat-1.20.tar.gz
root@ns2:~# tar -zxvf sqstat-1.20.tar.gz
root@ns2:~# mv sqstat-1.20 /var/www/
root@ns2:~# cd /var/www/
root@ns2:/var/www# mv sqstat-1.20 sqstat
root@ns2:/var/www# mv config.inc.php.defaults config.inc.php
root@ns2:/var/www# vim /var/www/sqstat/config.inc.php

//===================== Change the following settings =====================//
// Maximum URL length to display in URI table column
DEFINE("SQSTAT_SHOWLEN",100);

/* proxy settings */
/* Squid proxy server ip address or host name */
#$squidhost[0]="127.0.0.1";
$squidhost[0]="192.168.1.11";

/* Squid proxy server port */
#$squidport[0]=3128;
$squidport[0]=8080;

root@ns2:/var/www# /etc/init.d/squid restart
root@ns2:/var/www# /etc/init.d/apache2 restart


Log analysers: Webmin & sarg

Webmin & SARG installation:

Webmin installation: 
root@ns1:~# vim /etc/apt/sources.list
deb http://download.webmin.com/download/repository sarge contrib     //add this line
root@ns1:~# cd /root
root@ns1:~# wget http://www.webmin.com/jcameron-key.asc
root@ns1:~# apt-key add jcameron-key.asc
root@ns1:~# apt-get update
root@ns1:~# apt-get install webmin
root@ns1:~# apt-get install quota quota-tools

You should now be able to login to Webmin at the URL http://localhost:10000/.
Or if accessing it remotely, http://your_ip_address:10000/.

Alternative way:
you can also install webmin from deb file.
root@ns1:~# wget http://downloads.sourceforge.net/project/webadmin/webmin/1.510/webmin_1.510-2_all.deb
root@ns1:~# sudo dpkg -i webmin_1.510-2_all.deb

Open your web browser and enter the following address:
https://server_ip_address:10000/


Sarg installation
root@ns1:~# apt-get install sarg
We should now be able to login to sarg at the URL https://192.168.200.89/squid-reports/

Creating auto genarating report in a espasific time:
root@ns1:~# contrib mmhhddMMWW sarg -l/var/log/squid/access.log

If we want to use sarg from Webmin then:
sarver> Squid Report Generator> Generate report> select FILE/PERIOD> select ip

How to fix a apt-get broken packages in linux

Trouble-shooting experience
How to fix a apt-get broken packages in linux

Sometime we have experienced some apt-get broken packages in linux. For that broken package, we get the "apt-get install -f" message if we tried to install any kinds of packages in the box. And the funny thing is eather "apt-get install -f" or "apt-get --purge remove packagename" nothing will work in that periods of time. :D If you are also pulling your hairs for this problem, here is the solution. Do it step by step and check with update and upgrade to see problem's present status. If the problem still exits then move forwards to the next steps.

# Update your package list:
mahidul@mahidul:~$ sudo apt-get update

# Clean up any partial packages:
mahidul@mahidul:~$ sudo apt-get autoclean

# Clean up the apt cache:
mahidul@mahidul:~$ sudo apt-get clean

# Clean up any unneeded dependencies:
mahidul@mahidul:~$ sudo apt-get autoremove

# Identify the broken package and forcefully remove it:
mahidul@mahidul:~$  sudo dpkg --remove --force-all packagename
i.e.
mahidul@mahidul:~$  sudo dpkg --remove --force-all mysql-server-5.5

# Manually remove the package and again remove the offending packages. You have to remove broken package related softwares too, i.e
mahidul@mahidul:~$ cd /var/lib/dpkg/info
mahidul@mahidul:/var/lib/dpkg/info$ sudo rm mysql-server*
mahidul@mahidul:~$  sudo dpkg --remove --force-all mysql-server-5.5

# Now uninstall the service normally:
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get --purge remove mysql-server

# Now update and upgrade your server for the final time:
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get update
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get upgrade

Yepee!!!... Problem is solved now. :D