Ubuntu Intrepid - Installing MySQL (with Rails and PHP options)
Installing MySQL on Ubuntu Intrepid is very simple using the 'aptitude' package manager.
This article will go through the install process and also look at what other packages are need for MySQL to integrate with Ruby on Rails and with a standard PHP install.
MySQL install
To begin with, a simple MySQL install:
sudo aptitude install mysql-server mysql-client libmysqlclient15-dev
Note that we have installed the development libs and headers with the 'libmysqlclient15-dev' package - you can leave that out but I have found that they are useful in many siutations.
MySQL Password
During the installation of MySQL, you will be presented with the option to install a password:

Setting the MySQL Root password is a recommended step in setting up your Slice. However, it is, of course, up to you.
Should you decide that protecting your production database is a good idea, then simply enter your chosen password as directed.
After entering the password, Ubuntu Intrepid asks for a confirmation (which is a good thing!):

Done. It really is as simple as that.
MySQL and Ruby on Rails
I am assuming you have Ruby on Rails installed at this stage (if not, please see the Ubuntu Intrepid - Ruby on Rails article).
All we need to do is install one package as follows:
sudo aptitude install libmysql-ruby1.8
Seem suspiciously easy. Let's conduct a quick test to see if all is well:
irb
...
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> exit
That seems fine to me.
MySQL and PHP
If you installed Apache and PHP using the Ubuntu Intrepid - Apache and PHP article, you will already have the PHP MySQL module installed (which is 'php5-mysql').
This simple process also installs the PHP 'mysqli' (MySQL improved extension) module. This allows for much more powerful MySQL usage within PHP - please see the PHP mysqli page for more details.
A standard phpinfo page shows the following information for the mysql and mysqli modules:

As you can see, installation is very easy.
Summary
Installing MySQL via the 'aptitude' package manager is very simple and ensures you have any security updates if and when they are released.
Installing the necessary packages for MySQL to integrate with Ruby on Rails and PHP is a suitably easy process — allowing you to concentrate on the site design rather than messing with the installation itself.
—
Mike


Article Comments:
Torey Heinz commented Mon May 04 15:40:01 UTC 2009:
Is there a trick I am missing? For me to require 'mysql', I first have to require 'rubygems'.
feh commented Tue May 05 13:24:54 UTC 2009:
@tony
if you installed mysql via gems (possibly another gem depended on it. do a 'gem list mysql'), then that makes sense. if you dont want to 'require "rubygems"', either 'gem uninstall mysql' (may break dependencies) and use the ubuntu package, or put 'require "rubygems"' in your .irbrc
if you didn't install mysql via gems, then i have no idea, sorry. but the irbrc trick will still work
feh commented Tue May 05 13:25:39 UTC 2009:
whoops meant @torey
incolo real estate commented Thu Aug 13 23:20:51 UTC 2009:
thanks Mike for this helpful article.
what is the point of the passenger on rails?
Lenart commented Mon Sep 28 15:43:16 UTC 2009:
If you want to use UTF-8 as your default characterset you should:
Glenn commented Mon Oct 05 21:09:28 UTC 2009:
Lenart, those 4 lines did not work for me so i have skipped this but it did seem like a good idea! if anyone knows the correct lines i'm sure we'd all like to know them :)
Brian commented Mon Nov 23 07:29:31 UTC 2009:
I think the fix to Lenart's comment is to change utf8generalci on the last line to utf8generalci:
j commented Sun Apr 11 21:38:14 UTC 2010:
i followed these instructions to get mysql & ruby 1.9.1 working on ubuntu karmic.
initially this gave an error when doing the quick test in irb:
LoadError: no such file to load -- mysql from (irb):1:in
require' from (irb):1 from /usr/bin/irb:12:in<main>'it seems running a quick 'sudo gem install mysql' has fixed the issue