Ubuntu Hardy - Installing MySQL (with Rails and PHP options)
Installing MySQL on Ubuntu Hardy 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.
Unlike previous Ubuntu releases, Hardy asks for a confirmation of the password (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 Hardy - 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 Hardy - 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 ensure 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.
PickledOnion.


Article Comments:
Trustys commented Tue Jul 15 15:48:44 UTC 2008 ago:
It might be helpful if you explain how one goes about getting phpinfo page to display.
AMR commented Wed Jul 16 20:28:21 UTC 2008 ago:
You get phpinfo to display by creating a php file (like "test.php") containing the code
<?php phpinfo(); ?>
william commented Fri Jul 25 18:09:06 UTC 2008 ago:
Great tutorial as always PickledOnion
I had a typo with the mysql-server, and had to reexecute the command:
sudo aptitude install mysql-server mysql-client libmysqlclient15-devAll went well, but I encountered some error with apparmor. Any pointers on what went wrong here?
Setting up apparmor (2.1+1075-0ubuntu9.1) ... $Mounting securityfs on /sys/kernel/security: done. ls: cannot access /sys/module/apparmor: No such file or directory ls: cannot access /sys/module/apparmor: No such file or directory $Loading AppArmor module: Failed. invoke-rc.d: initscript apparmor, action "start" failed. ls: cannot access /sys/module/apparmor: No such file or directory ls: cannot access /sys/module/apparmor: No such file or directory ls: cannot access /sys/module/apparmor: No such file or directory $Loading AppArmor module: Failed. invoke-rc.d: initscript apparmor, action "reload" failed.
Setting up exim4-config (4.69-2) ...
Setting up exim4-base (4.69-2) ...
Setting up exim4-daemon-light (4.69-2) ...
Setting up exim4 (4.69-2) ...
Setting up libhtml-template-perl (2.9-1) ... Setting up liblockfile1 (1.06.2) ... Setting up mailx (1:8.1.2-0.20071017cvs-2) ...
Setting up mysql-server (5.0.51a-3ubuntu5.1) ... Setting up apparmor-profiles (2.1+1075-0ubuntu9.1) ... ls: cannot access /sys/module/apparmor: No such file or directory ls: cannot access /sys/module/apparmor: No such file or directory ls: cannot access /sys/module/apparmor: No such file or directory $Loading AppArmor module: Failed.
kamal thakur commented Sun Aug 17 22:08:51 UTC 2008 ago:
I got a similar problem
Daniel Hirsch commented Fri Aug 29 02:44:50 UTC 2008 ago:
I ran into the problem that William mentioned. Turns out (many thanks to Tony on the chat channel), apparmor is to blame -- it doesn't play nice with VPS.
So instead, you get use apt-get instead of aptitude, which won't try and install apparmor.
PickledOnion commented Fri Aug 29 11:12:58 UTC 2008 ago:
Hi,
I tried to replicate the apparmor issues you are experiencing and I can't.
I used a fresh Hardy Slice, completed the basic setup (see setup part 1 and part 2) and sailed through the mysql installation as shown above.
I even looked at the kernels but that is not the issue either.
I don't know what to suggest as I simply can't replicate it.
PickledOnion