ibdata1 mysql file

Posted by | Posted in Code, Command-Line, Linux, MySQL, Ubuntu | Posted on 31-07-2014

Recently I discovered that my ibdata1 file with in /var/lib/mysql was filling up my webserver hard drive. After reading on several forums, it was discovered that the ibdata1 file contains all of the InnoDB file structure as-well-as all of the data. You can not delete this file and have mysql recreate it. You will lose all of your MySQL InnoDB information.

Instead, you’ll have to backup all of your InnoDB databases, drop all of your InnoDB databases, stop the mysql server, remove the corresponding files, restart myssql, recreate your databases and then restore all your databases.

Below, I’ll demonstrate the steps that I took to accomplish this task.

Backing up your InnoDB MySQL Database

mysqldump -u USER --password=PASS DATABASE > DATABASE_DATE.sql

Drop your MySQL InnoDB Database

mysql -u USER --password=PASS
drop database DATABASE;

Stop MySQL Server

sudo service mysql stop

Remove the offending files

sudo rm /var/lib/mysql/ibdate1
sudo rm /var/lib/mysql/ib_logfile0
sudo rm /var/lib/mysql/ib_logfile1

Restart MySQL

sudo service mysql start

Recreate your InnoDB MySQL Database

mysql -u USER --password=PASS
create database DATABASE;

Restore your database from backup.

cat DATABASE_DATE.sql | mysql -u USER --password=PASS -D DATABASE

Now you should be all set and your ibdata1 file will be MUCH smaller.

Problem upgrading from Ubuntu 10.10 to 11.04 on Mac Pro no bootable device found

Posted by | Posted in Command-Line, OS X, Ubuntu | Posted on 14-11-2011

Recently, I had an issue upgrading my Mac Pro from Ubuntu 10.10 to 11.04. After the install and the initial reboot I received a “No Bootable device found”. This isn’t the first time that this has happened to me during a Mac Pro Ubuntu upgrade. Many tech boards had offered the reset your PRAM or reset your Open Firmware as the solution to re-detecting the ubuntu partition. All had failed. Resetting your PRAM and your Open firmware won’t tell the system that “X” partition is bootable. Ultimately it came down to re-blessing the ubuntu partition with in OS X.

I used a Mac OS X startup disk to gain access to a terminal session to run the bless command.

/usr/sbin/bless --device /dev/disk2s1 --setBoot --legacy

Creating a SSH Tunnel

Posted by | Posted in Command-Line, Guides, Linux, OS X, Server, SSH, Tunneling, Ubuntu | Posted on 01-02-2011

To traverse firewalls that block incoming SSH connections or to access a computer with a non routable IP address, you can create an SSH tunnel. When creating a SSH tunnel, you’ll generate the tunnel on the host system and connect it to another system.

With the SSH command, you’ll use the “-R” flag, that allows reversible communications or a reverse tunnel.

This command that I normally use:

It states, create a reversible SSH tunnel from this localhost port 22 to USER@SERVER on port 10000.

/usr/bin/ssh -R 10000:localhost:22 USER@SERVER

You’ll need to leave this connection open otherwise the tunnel will collapse. Normally I execute a program at the other end to keep the connection alive. Some SSHd configurations will drop connections due to inactivity.

To connect to the tunnel from USER@SERVER:

use ssh to connect to your USER account on the host server via port 10000.

/usr/bin/ssh USER@localhost -p 10000

this will give you the login prompt at the host server. User your login information or you can also setup SSH Keys.

How to get rid of cron warnings

Posted by | Posted in Bash, Code, Command-Line, Cron, Linux, OS X, Server, Ubuntu | Posted on 31-01-2011

If a cron job executes with unmanaged warnings for data, you’ll generate LOTS of emails to your account. Here is an easy way to redirect all that extraneous data.

Just add “>> /dev/null 2>$1″ to the end of each of your cron jobs.

0,10,20,30,40,50 * * * * /path/to/script >> /dev/null 2>&1

PHP and $argv

Posted by | Posted in Code, Command-Line, Functions, Guides, Linux, OS X, PHP, Server, Ubuntu | Posted on 31-01-2011

I’ve been adding $argv functionality to all of my PHP maintenance scripts. I am doing this, so I don’t have to edit a variable each time I want to execute it.

A PHP $argv example.

< ? PHP
#	test.php
#	demonstration of $argv
#	Dan McCoy
#	January 31 2011
$command = $argv[1];
$GLOBALS['script'] = basename($argv[0]);
$GLOBALS['ver'] = "1.0";
$GLOBALS['file'] = $argv[2];
function help() {
	echo "Help for ". $GLOBALS['script'] ."\n";
	echo "-h \t Help prompt \n";
	echo "-v \t Version ". $GLOBALS['ver'] ."\n";
	echo "-g \t Grab file from X \n";
	echo "-f \t Reformat data from X \n";
	echo "-l \t Load data from X \n";
}// end help
function grab(){
	@exec('/opt/local/bin/wget http://webserver.com/page.php -O '. $GLOBALS['file'],$retval);
	return "Grab completed ". $retval[0] ." \n";
}// end grab
function reformat() {
	$fp = $GLOBALS['file'];
	$file = fopen($fp,'r');
	$data = fread($file,filesize($fp));
	$data = str_replace("<br /><br />","\n\n",$data);
	$data = str_replace("<br />","\n",$data);
	$data = strip_tags($data);
	$data = str_replace("\t","",$data);
	$fp = $GLOBALS['file'];
	$file = fopen($fp,'w');
	return "Reformating completed \n";
}// end reformat
function load() {
        $fp = $GLOBALS['file'];
        $file = fopen($fp,'r');
        $data = fread($file,filesize($fp));
	return $data;
function delete() {
	$ret = @unlink($GLOBALS['file']);
	if ($ret==TRUE){
		return "File has been deleted \n";
		return "There was an ERROR deleting ". $GLOBALS['file']."\n";        
}// end delete
function switch_default() {
	echo "Command not found \n";
switch($command) {
	case "-h":
	        echo help();
	case "-g":
        	echo grab();
	case "-f":
		echo reformat();
	case "-l":
		echo load();
	case "-d":
		echo delete();
}// end switch
? >

Executing more then 1 command at once

Posted by | Posted in Bash, Code, Command-Line, Cron, Linux, OS X, Server, Ubuntu | Posted on 30-01-2011

Many times, I have to execute sequential commands inorder to complete a task. Below is an example of how to do this.

/path/to/command argv1 && /path/to/command argv2

I normally use this sequential order when pulling raw data from a source and then reformatting it for my needs.

15 * * * * /usr/local/bin/pullsource grab && /usr/local/bin/pullsource reformat

Change the default crontab editor – Bash

Posted by | Posted in Bash, Code, Command-Line, Cron, Guides, Linux, OS X | Posted on 30-01-2011

You can change your default crontab (crontab -e) by setting the EDITOR environment variable in BASH:

hostname# which vi
hostname# export EDITOR=/usr/bin/vi
hostname# set | grep EDITOR

Applescript – folder and file counter

Posted by | Posted in Applescript, Code, OS X | Posted on 16-09-2010

set theFolder to (choose folder)
set thePath to POSIX path of theFolder
set fileCount to 0
set folderCount to 0
tell application "Finder"
	set theFileList to every item in folder theFolder
	repeat with x in theFileList
		if not character 1 of ((name of x) as string) is equal to "." then
			if kind of x is equal to "Folder" then -- "folder" depends fromĀ  the finder language 
				set folderCount to folderCount + 1
				set fileCount to fileCount + 1
			end if
		end if
	end repeat
end tell
display dialog "There are " & folderCount & " folders andĀ  " & fileCount & " files in " & thePath

Applescript – Change folder color based on size

Posted by | Posted in Applescript, Code, OS X | Posted on 16-09-2010

property theFile : missing value
property theFolder : "test"
property thePosixPath : "/Users/user/Desktop/"
property theAliasPath : "Users:USER:Desktop:"
property theSize : missing value
tell application "Finder"
	set theSize to do shell script "du -s -k " & thePosixPath & theFolder & " |awk '{print $1}'"
	if theSize > 700000 then
		set label index of (folder theAliasPath & theFolder) to 2
	end if
end tell

Epson 4800 Maintenance Required 0002 Error Code – Reset Key Sequence

Posted by | Posted in Epson, Hardware, Printer, Stylus Pro 4800 | Posted on 21-04-2010

This afternoon, one of our Epson Stylus Pro 4800 printers developed a maintenance required 0002 error code. The code refers that the Carriage Return Motor or CR Motor has reached the end of its life and should be replaced. At the time this Epson 4800 had printed 16,195 prints and had transferred the print head (carriage) back and forth 4,995,102 times.

To reset the CR Motor count, you have to enter “Service Mode 2″. To do this, follow the following steps.

1. Turn off your Epson 4800.
2. Hold down the Pause, down and menu buttons.
3. Restart the Epson 4800 while holding down the buttons mentioned above.
4. Continue to hold the buttons down until you see “Service Mode 2″.
5. Use the up and down arrows to navigate to clean counts.
6. Locate the CR Motor count.
7. You should see an “Exec” on the screen.
8. Use the right arrow to select “Exec”.
9. Press the menu right arrow one more time to execute the clear command.
10. power off and then power back on your printers. The error should be cleared.

Note: Your print quality may degrade with time. Epson recommends that you replace the CR motor when this error appears.

Join the mailing list

Check your email and confirm the subscription