Installing MySQL 5.0 on Solaris 10

By Simon Varney on 19 Dec 2008

Why not just use the CoolStack version from the CSKamp package?

We use Sun’s CoolStack but the MySQL version included in 1.3.1 is a release candidate version of MySQL 5.1:

# mysql --version
mysql  Ver 14.14 Distrib 5.1.25-rc, for pc-solaris2.10 (i386) using readline 5.1

Even the GA “production” release of MySQL 5.1 has caused a lot of controversy as it contains some serious bugs (see here, and here).

For this reason we install MySQL 5.0 for our clients.

For those unfamiliar with installing software on Solaris you might be frustrated when it doesn’t just work™. So this is going to a quick run through of the process.

I’ll be installing the 32bit version of MySQL 5.0 on an x86 Solaris box.

Installing MYSQL 5.0 on Solaris 10

Download and installation

# wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67-solaris10-i386.pkg.gz/from/http://mirrors.dedipower.com/www.mysql.com/
# gunzip mysql-5.0.67-solaris10-i386.pkg.gz
# pkgadd -d mysql-5.0.67-solaris10-i386.pkg

The following packages are available:
  1  mysql     MySQL Community Server (GPL)
               (i86pc) 5.0.67

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:

Processing package instance  from 

MySQL Community Server (GPL)(i86pc) 5.0.67
Copyright (C) 2000-2005 MySQL AB & MySQL Finland AB & TCX DataKonsult AB

This install require that the user 'mysql' and group 'mysql' exists
pkgadd: ERROR: request script did not complete successfully

Installation of  failed.
No changes were made to the system.

Oh dear, first problem: we don’t have a mysql user and group. It could have created them for us – but it doesn’t.

# mkdir /var/lib
# groupadd -g 800 mysql
# useradd -m -u 800 -g mysql -d /var/lib/mysql -s /usr/bin/bash -c 'MySQL' mysql
# chmod 750 /var/lib/mysql

note: to be on the safe side check that the uid and gid are available first cat /etc/passwd and cat /etc/group – or just remove those options and they will be assigned automatically.

We’ll just clear our the junk that useradd put into the mysql home directory:

# rm -rf /var/lib/mysql/*

So now we can add the package:

# pkgadd -d mysql-5.0.67-solaris10-i386.pkg
...
Installation of mysql was successful.

Great!

Getting it setup

The package tries to run the install script but fails. This is no problem though we can do it ourselves.

Run the MySQL install script – which adds the db, etc:

# /opt/mysql/mysql/scripts/mysql_install_db --datadir=/var/lib/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
...

Older versions may have left init scripts lying around carelessly, we can remove this:

# for x in `find /etc/rc* /etc/init.d | grep -i mysql`; do rm $x; done

Adding MySQL to SMF

You’ll want to add MySQL to SMF to enable Solaris to control this process and restart it if it fails. See this post for a basic guide to SMF.

This will download the manifest file that we use from here.

# cp /opt/mysql/mysql/support-files/mysql.server /opt/mysql/mysql/bin/
# mkdir /var/svc/manifest/application/database
# wget -O /var/svc/manifest/application/database/mysql.xml http://svn.everycity.co.uk/public/solaris/manifests/MySQL.xml
# svccfg validate /var/svc/manifest/application/database/mysql.xml
# svccfg import /var/svc/manifest/application/database/mysql.xml

You can now start the service!

# svcadm enable mysql

Configuring the privileges

You are currently running a very unsafe installation – there is no root password. We’d better set one:

# mysql -u root

Once you’ve got a mysql prompt we use this to create a root user that can access the database from any host (modify this as needed):

mysql> use mysql;
mysql> delete from user where user != 'root';
mysql> delete from user where host != 'localhost';
mysql> update user set password = password('YOURROOTPASSWORD');
mysql> update user set host = '%';
mysql> flush privileges;
mysql> q

All done!

You can view the status of the mysql service with:

# svcs -a | grep mysql
online         14:29:27 svc:/application/database/mysql:default