Tuesday, November 8, 2011

[solved] MYSQL Can't start server: can't create PID file: No space left on device



Hi all dear friends of HTV, today i will explain how to fix a bug that affects MySQL server running on a Centos 5.0 Box.

The error in the /var/log/mysqld is :

Can't start server: can't create PID file: No space left on device MYSQL

If your MySQL can't restart and the /var/log/mysqld log show you this message, well, most probably you finished your partition space available.

To solve this issue you have to do the following steps:

1) check your partitions with the command:

df -h

this command will output your partitions conf:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              58G   53G   0  100% //dev/sda1              99M   12M   83M  13% /boot
/dev/sda2              58G   13G   42G  24% /media/sda2



Please notice that the full size of /dev/sda2 partition is 58GB, the used space is 53GB and the available once is 0 (100% use).


2) Now that we are aware of this we have to find the files (often they are huge log files) that fill our partition. So we could take a look in the /var directory or /tmp directory to find and move some of them via rsync into another partition or we could free some space deleting older logs and files not needed. (Be carefully when you are doing that).
To find big files over your system you could execute this command via ssh


 du -h --max-depth=3 /* > mybigfiles.txt


This command will write in the file all the output of the command du -h -max-depth=3 in the file named mybigfiles.txt all showing all the dirs in the system with theirs current size.

Navigating through this file you could find which directories are the biggest ones and after that you have to clean them before restarting MySQL server.

First of all do this command via cmd line:

yum clean all

To empty cached sources and packages in your RH distro.

Then if you would like to remove, for example, all the log files in a dir older then 3 days you have to execute the command :


find /var/log/mydirectorywithbigfiles -type f -mtime +3 -exec rm {}


or use this bash script


#!/bin/bash

find /var/log/mydirectorywithbigfiles -type f -mtime +3 -exec rm {} \;

  

that use a combo of find command and -exec rm {} that removes all the files inside that dir.

After that please execute again the command to check if you freed up some disk space.


df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              58G   13G   42G  24% //dev/sda1              99M   12M   83M  13% /boot
/dev/sda2              58G   13G   42G  24% /media/sda2



Once finished, please restart your Mysqld daemon, via /etc/init.d/mysqld start.


Leave a comment if you liked this guide.


HTV




7 comments:

Blogue do Gibloy said...

Very good tips, my log file was with 24G of site. I deleted it and now I need to study how to avoid it getting too big, if it's possible in Linux...

Anonymous said...

Thank you very much. It is really useful and very well explained. Excellent!

Arul Dhandapani said...

Super! this is what the exact solution.

mickeyze said...

Thank you very much! U saved my day!

Anonymous said...

You saved my life :) Thanks you!!

Anonymous said...

This worked perfect!

Pratik Bandal said...

Thanks boss!!!very useful!!!
----Pratik Bandal