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:

MySQL password request

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!):

MySQL password confirmation

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:

require 'mysql'
#=> true

That seems fine to me.


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:

phpinfo mysql and mysqli information

As you can see, installation is very easy.


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.


Article Comments:

Trustys commented Tue Jul 15 15:48:44 UTC 2008:

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:

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:

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-dev

All 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) ...

  • Starting MTA ...done.

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:

I got a similar problem

Daniel Hirsch commented Fri Aug 29 02:44:50 UTC 2008:

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:


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.


Dale commented Fri Oct 03 14:34:57 UTC 2008:

Hi Pickled Onion

  • I got through setup 1 & 2 and mysql but the irb doesn't work. What do I add to the PATH in '.profile'?

  • When I type 'ls' I get nothing....

  • typing 'sudo /usr/sbin/update-locale LANG=en_US.UTF-8' yields:

* update-locale: Error: invalid locale settings: LANG=en_US.UTF-8

Any clues?

Thanks, Dale

marvin commented Wed Oct 22 06:07:55 UTC 2008:

Hey pickled Onion,

I was wondering I saw your turn off innodb on the gutsy installation instructions, should we doing the same for the mysql hardy installation to minimize memory usage.

Joe commented Wed Oct 22 15:03:40 UTC 2008:

So if the apparmour failed do we go about 'aptitude remove apparmour mysql-server mysql-client libmysqlclient15-dev'

then 'apt-get install mysql-server mysql-client libmysqlclient15-dev' ??

I don't want apparmour dependencies on my system if they're not needed I want to make sure this setup is as clean as possible..

Joe *solved* commented Fri Oct 24 07:13:20 UTC 2008:

aptitude purge apparmour apt-get install mysql-server mysql-client libmysqlclient15-dev

Alan Francis commented Fri Oct 31 11:32:50 UTC 2008:

First off, these tutorials are excellent.

I'm a little puzzled about why installing mysql 'required' the installation of exim and apparmor ?

I didn't want an MTA and I don't even know what apparmor is. Can I remove them safely ? They didn't seem to install with mysql on Gutsy ?


henry commented Tue Nov 04 22:40:17 UTC 2008:

Exim4 eats memory. Apparmor only protects CUPS by default in Ubuntu. I basically uninstalled them.

sudo aptitude purge exim4 sudo aptitude purge exim4-base sudo aptitude purge apparmor

Don commented Sat Nov 29 00:13:16 UTC 2008:

loading Joomla 1.5x but can't get past the building of the dB. Doesn't go to the next screen. How can I check to see if it is a Mysql issue?

I have Ubuntu as the OS, Apache2, Mysql,PhP and PhPmyadmin installed. I can see the dB using PHPmyadmin and I can add tables.

cs commented Thu Dec 11 12:26:43 UTC 2008:

After installing MySQL you should check the installation with MySQLTuner: http://wiki.mysqltuner.com/MySQLTuner. It takes only 30 secs.

There are pretty much to tune-up & configure after the 'raw' installation presented in this article.

Luke commented Sat Jan 10 04:54:44 UTC 2009:

I had the same problems as described above installing MySQL in that the server failed to start during the installation process. I commented out the following line in /etc/mysql/my.cnf which seemed to fix it for me:


I also used apt-get to install MySQL to avoid the apparmour troubles described above.

sudo apt-get install mysql-server mysql-client

Daniel Haran commented Sun Feb 01 15:40:35 UTC 2009:

Package files were not downloading properly for me

Err http://archive.ubuntu.com hardy-updates/main mysql-common 5.0.51a-3ubuntu5.1 404 Not Found [IP: 80] ... Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common5.0.51a-3ubuntu5.1all.deb 404 Not Found [IP: 80]

"sudo aptitude update" fixes it

Matt Davies commented Wed Feb 25 11:57:21 UTC 2009:

Is it ok to leave the mysql install as is once you've installed it?

I used to have to remove certain accounts, ones with no passwords. If I do that will I break the install?

ragi commented Fri Apr 17 06:21:56 UTC 2009:

It also easy to install mysqldb a package to use mysql with python... sudo apt-get install python-mysqldb

Rob commented Mon Jul 27 20:06:29 UTC 2009:

I have the same problem as Dale.

$ sudo aptitude install libmysql-ruby1.8 Reading package lists... Done Building dependency tree
Reading state information... Done Reading extended state information
Initializing package states... Done Building tag database... Done
No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. Writing extended state information... Done Reading package lists... Done
Building dependency tree
Reading state information... Done Reading extended state information
Initializing package states... Done Building tag database... Done
$ irb -bash: irb: command not found

Steve commented Sun Aug 02 23:57:32 UTC 2009:

I could use a tutorial on configuring things to allow for remote connection to mysql from my machine.

If anyone has a good lead please let me know.


Sam Wierema commented Sat Jan 09 13:05:27 UTC 2010:

When installing MySQL I ran into some problems with Apparmor and MySQL wouldn't. Using Joe's comment I first removed Apparmor:

aptitude purge apparmor; aptitude install mysql-server mysql-client libmysqlclient15-dev (make sure to run it as root, or with sudo)

Then, using Luke's comment I edited /etc/mysql/my.cnf and changed the line where it says:

bind-address: To my local slice IP: bind-address: 12.345.67.89 (use a real IP!)

Then started MySQL with

/etc/init.d/mysql start and it worked.

nicolas block commented Fri Jan 15 03:58:51 UTC 2010:

This is a reasonable explaination of how to configure a slice as a dedicated mysql server.


Bas commented Mon Aug 16 12:29:22 UTC 2010:

And to make it a little easier you can use phpmyadmin:

apt-get install phpmyadmin

And to set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf:

Include /etc/phpmyadmin/apache.conf

from: http://www.howtoforge.com/ubuntudebianlamp_server

Want to comment?

(not made public)


(use plain text or Markdown syntax)