-
Installing MySQL gem for Ruby 1.9.x
As of this writing, the MYSQL gem cannot be installed by simply doing a GEM INSTALL with ruby 1.9.1. In order to install the gem, follow these easy steps.
First download the mysql gem from rubyforge, and unzip it:
sudo wget http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz sudo tar -xzvf mysql-ruby-2.8.1.tar.gz cd mysql-ruby-2.8.1 -
Finding Duplicate Fields in a Database Table
Occasionally it is necessary to find duplicate fields within a database table. The following query can be used to accomplish this easily.
SELECT *
FROM 'table'
WHERE ('item' IN (SELECT 'item'
FROM 'table'
GROUP BY 'item'
HAVING COUNT(*) > 1))
ORDER BY 'item'
This will list all rows in the desired ‘table’ where the given field (‘item’) is duplicated. This is a great query to use if you want to find duplicate email addresses in a database, or any other field that may be duplicated. -
Setting Up Ubuntu for Rails Development
These are a the procedures we use to setup a PC or VM for development of a ruby on rails application.
First things first, get your install software ready. These instructions are based on the Hardy Heron version of Ubuntu (8.04).
Install the base OS and then fire up the terminal so you can copy and paste the following commands.
So once you have the base installed, make sure your distribution is up to date:
sudo apt-get update sudo apt-get dist-upgrade -
Installing the Mysql Gem
This is just a self reminder. I always seem to forget the dev package that is required to build the mysql gem. Failure to install this results in all kinds of headaches:
sudo apt-get install libmysqlclient15-devThen install the gem and you are all set:
sudo gem install mysql -
Simple Script to Backup Smaller MYSQL Databases remotely
Here is a simple script you can use to add as a job that you can use to backup smaller remote MYSQL DB’s. This script will take a mysql dump, date it, then add it to an archive (with the date), then the uncompressed file is deleted. It is perfect to use as a daily cronjob. The instructions are specifically for Ubuntu, but it can be easily modified for Unix or even a Windows batch file.