MySQL Problems – a complete reinstall

I rebooted an Ubuntu 12.04 server after upgrading the kernel and MySQL.  However, I found that the new MySQL would not start. When I tried:

sudo service start mysql

I got:

start: job failed to start

There were no errors appearing in the /var/log/mysql/error.log and so there was no information to help debug it.  I found this post and tried every single one of the solutions.  When I removed mysql-server-5.5 using:

apt-get –purge remove mysql-server
rm /etc/mysql/ -R

I found the when I reinstalled mysql-server the installation would fail saying:

Unable to set password for the MySQL “root” user  An error occurred while setting the password for the MySQL administrative user. This may have happened because the account already has a password, or because of a communication problem with the MySQL server.

I then got stuck because I could no longer remove MySQL because it was only partially installed.  Every time I tried to remove it, it would ask me to put in a new root password which I obviously could not do.  The solution is to use dpkg to purge the partially installed package:

dpkg –purge mysql-server-5.5

Then I tried reinstalling again and got:

Can’t find file: ‘./mysql/host.frm’ (errno: 13)

Basically, the solution to these problems is a complete purge of MySQL and removing ALL of it and start again.  I found what mysql related packages I have install by running:

dpkg –get-selections | grep mysql

and found I had:

libdbd-mysql-perl
libmysqlclient18
mysql-client-5.5
mysql-client-core-5.5
mysql-common
mysql-server
mysql-server-5.5
mysql-server-core-5.5
mysqltuner
php5-mysql

I removed all them!

apt-get –purge remove mysql-server
apt-get –purge remove mysql-client
apt-get –purge remove mysql-common
…… etc …. etc…

Then cleared the apt-get cache and removed the mysql config and data directories (I have a backup of the data from the night before.)  Note – these commands will remove all your old MySQL data, so don’t run them if you don’t have a backup or you don’t care about the data.

apt-get autoremove
apt-get autoclean
rm /etc/mysql/ -R
rm /var/lib/mysql/ -R

Then reinstalling mysql-server and the other packages.

apt-get install mysql-server
etc….

What a massive waste of time!  Oh well – I hope this post helps someone else out of this pickle.

Monitoring HP Raid Array on Ubuntu Server

I wanted to monitor our HP server raid array on Ubuntu 12.04.  I  am sure that there is a good way of setting this up with Nagios or SMNP – however, I thought I would write a little bash script which emails me if any of the hard drives in the raid array fail.  I assume that you have already installed the HP Proliant Support Pack perhaps using these instructions.

To send an email from command line you will also need mailx.  This is a virtual package on Ubuntu and I tend to install bsd-mailx.  To install it run:

sudo apt-get install bsd-mailx

It will also install Postfix (if this isn’t already setup).  When configuring Postfix, I selected “Internet Site” and entered the hostname of the server.

Here is the bash script that I wrote.  The indentation seems to have got lost but you should be able to recreate it.

#!/bin/bash

# Email settings
email_recipient=”your.email@somewhere.com”

# Current datetime in YYYY-MM-DD_HH-MM-SS
date=`date +”%Y-%m-%d_%H-%M-%S”`

# Make sure the log directory exists.
/bin/mkdir -p /root/harddrive_check/log

log_filename=”/root/harddrive_check/log/$date.log”

hostname=`hostname`

if hpacucli ctrl all show config | grep -q “Failed”; then

echo -e “Harddrive Check Run: `date`” > $log_filename

echo -e “\nUsing Command: hpacucli ctrl all show config” >> $log_filename

hpacucli ctrl all show config >> $log_filename

email_subject=”Harddrive Failed On $hostname”

/usr/bin/mailx -s “$email_subject” “$email_recipient” < $log_filename

fi

I then setup a cronjob on the server.

crontab -e

Adding the line:

0 * * * * /root/harddrive_check.sh

I hope this is helpful to someone.  Let me know if you know a better way of doing this. Thanks for reading.