How to install Mysql on Openbsd

This is valid for (at least) Openbsd 5.6, with the packages version of Mysql.

This is relatively simple, more as a reminder of what to do (or not).

1. Make sure pkg_add is configured correctly.

This goes without saying, but pkg_add should be configured correctly on your machine.

For more information, please refer to the Openbsd FAQ (see below).

(Essentially, you should export the variable PKG_PATH in your /root/.profile - nuff said)

2. Install all Mysql packages on the system.

Install all the packages for great justice!!

# pkg_add -v -i mysql-server                       
# pkg_add -v -i mysql-client mysql-utilities mytop 

This install the server, as well as the clients, various utilities and mytop}}, which I like very much. See below for the installation of {{{innotop which is also great...

3. Perform Mysql initialization.

As simple as:

# mysql_install_db --user=_mysql

The output of the command should be something like this:

# mysql_install_db --user=_mysql
WARNING: The host '' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
150113 15:28:11 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
Filling help tables...
150113 15:28:11 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

To do so, start the server, then issue the following commands:

/usr/local/bin/mysqladmin -u root password 'new-password'
/usr/local/bin/mysqladmin -u root -h password 'new-password'

Alternatively you can run:

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
/etc/rc.d/mysqld start

Please report any problems with the /usr/local/bin/mysqlbug script!

The only detail to remember here is that the Mysql user under Openbsd is _mysql of course...

Start the Mysql server with the rc.d script as usual:

# /etc/rc.d/mysqld start 

4. Perform Mysql secure installation.

Again, this should be mandatory for all Mysql installations, regardless of OS.

# mysql_secure_installation                                                                                                        


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Simple enough.

5. Test root login to the Mysql database

Again, simple enough:

A little bit of testing does not hurt:

# ps auxwww | grep -i [m]ysql
root     29236  0.0  0.1   712   668 p1  I      3:33PM    0:00.01 /bin/sh /usr/local/bin/mysqld_safe
_mysql   30125  0.0  1.7 42632 17924 p1  I      3:33PM    0:00.31 /usr/local/libexec/mysqld --basedir=/usr/local --datadir=/var/mysql 
--user=_mysql --log-error=/var/mysql/ --pid-file=/var/mysql/ --socket=/var/run/mysql/mysql.sock --port=3306

OK, we know it is running. Test:

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73-log OpenBSD port: mysql-server-5.1.73p0v0

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
| Database           |
| information_schema |
| mysql              |
2 rows in set (0.00 sec)

Everything is running OK!

6. Bonus round: installing innotop

Not especially useful, but innotop is actually quite good, and very easy to install under Openbsd:

Download the source code archive from the innotop web site (see below) unzip/untar the package, go to the correct directory and enter the following commands:

$ perl ./Makefile.PL                                                             
$ sudo make install                                                              

And you should be in business! =)

That was almost painless, right ?!

Hope this helps!

See Also: