OpenBSD Install MySQL Server

How do I install and run MySQL version 5 database Server under OpenBSD UNIX operating systemm?

OpenBSD has pkg_add command. It is used to install packages created with the pkg_create command. Selected packages containing precompiled applications from the /usr/ports tree can be found on the OpenBSD FTP site. The pkg_add is the easiest way to install new packages, to replace existing packages with other flavors (option -r) or to update packages to newer versions option -u). Please note that MySQL server dropped from the latest version of OpenBSD and replaced by MariaDB server. MariaDB intends to maintain high compatibility with Oracle MySQL servers. It is a drop-in replacement for MySQL server on OpenBSD. I strongly suggest that you install and set up MariaDB server on OpenBSD.

How to install MySQL Database Server on OpenBSD

First setup installation mirror i.e. PKG_PATH using export command:
$ export PKG_PATH=ftp://mirror.planetunix.net/pub/OpenBSD/4.1/packages/`machine -a`/
Next install MySQL server, using pkg_add command, enter:
$ sudo pkg_add -i -v mysql-server
OR
# pkg_add -i -v mysql-server
Output:

parsing mysql-server-5.0.33
Dependencies for mysql-server-5.0.33 resolve to: p5-DBD-mysql-3.0008, mysql-client-5.0.33 (todo: mysql-client-5.0.33,p5-DBD-mysql-3.0008)
mysql-server-5.0.33:parsing mysql-client-5.0.33
mysql-server-5.0.33:mysql-client-5.0.33: complete                                                                                                                             
mysql-server-5.0.33:parsing p5-DBD-mysql-3.0008
Dependencies for p5-DBD-mysql-3.0008 resolve to: mysql-client-5.0.33, p5-DBI-1.53 (todo: p5-DBI-1.53)
mysql-server-5.0.33:parsing p5-DBI-1.53
Dependencies for p5-DBI-1.53 resolve to: p5-PlRPC-0.2018p0 (todo: p5-PlRPC-0.2018p0)
mysql-server-5.0.33:parsing p5-PlRPC-0.2018p0
Dependencies for p5-PlRPC-0.2018p0 resolve to: p5-Net-Daemon-0.39 (todo: p5-Net-Daemon-0.39)
mysql-server-5.0.33:parsing p5-Net-Daemon-0.39
mysql-server-5.0.33:p5-Net-Daemon-0.39: complete                                                                                                                              
mysql-server-5.0.33:p5-PlRPC-0.2018p0: complete                                                                                                                               
mysql-server-5.0.33:p5-DBI-1.53: complete                                                                                                                                     
mysql-server-5.0.33:p5-DBD-mysql-3.0008: complete                                                                                                                             
adding group _mysql
adding user _mysql
installed /etc/my.cnf from /usr/local/share/mysql/my-medium.cnf****************************************************************************************************     | 97%
mysql-server-5.0.33: complete                                                                                                                                                 
--- mysql-server-5.0.33 -------------------
The mysql-server package doesn't initialize a default database.
Please run /usr/local/bin/mysql_install_db to create one.

Install default MySQL database

By default MySQL database is not initialized, enter the following command to create a default database:
# /usr/local/bin/mysql_install_db
Output:

Installing all prepared tables
Fill help tables
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
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 openbsd.nixcraft.in password 'new-password'
See the manual for more instructions.

Start MySQL server

Now you have MySQL server installed. Start the server daemon, enter:
# /usr/local/bin/mysqld_safe &
Output:

[1] 7750
Starting mysqld daemon with databases from /var/mysql

Connect to MySQL server

Run mysql command to test if everything is working fine, enter:
# mysql
Output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.33-log OpenBSD port: mysql-server-5.0.33

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit
Bye

Set root password

You must set a password for the MySQL root user, enter:
# /usr/local/bin/mysqladmin -u root password 'YOUR-Secret-Password'
To access the MySQL server with password, enter:
$ mysql -u root -p

Create MySQL startup and stop script

Finally, you need a script to start and stop MySQL Server. In order to start MySQL server at boot time, enter following command in /etc/rc.conf.local file:
# vi /etc/rc.conf.local
Append following line:
mysql=YES
Save and close the file. Now you need to edit /etc/rc.local file. It is use to specify site-specific startup actions, daemons, and other things which can be done AFTER your system goes into securemode:
# vi /etc/rc.local
Find out line which read as follows:
# Add your local startup actions here.
Append following code:

# MySQL startup 
if [ X"${mysql}" == X"YES" -a -x /usr/local/bin/mysqld_safe ]; then
   echo -n " mysqld " 
   /usr/local/bin/mysqld_safe --user=_mysql &
fi

Save and close the file.

How do I stop MySQL server under OpenBSD?

Use mysqladmin command:
# mysqladmin -u root -p shutdown


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Vidak Nov 7, 2008 @ 18:01

    This is the best manual for MYSQL5! It helped me to install, start and stop mysqld and use mysql on OpenBSD.
    Thanks

  • dve24 Jan 30, 2009 @ 11:52

    Great manual, my hardware supplier tries to convince me to OpenBSD, so I’m forced to configure my phpfusion (i.e. php+mysql) on it. Compared to Debian, it is HELL, but well…
    At least this manual helped me a bit :)

  • psi0nic Mar 17, 2009 @ 1:45

    GREAT TUTORIAL! I got the server up in seconds after finishing this tut on my MySQL server. :). THX very much.

  • bogdan May 13, 2009 @ 12:10

    Kool

    Ty very much nice very very nice

  • psi0nic Jun 22, 2009 @ 18:39

    Hymm…dunno what’s wrong…I get following error while setting up a mysql root password:
    /usr/local/bin/mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’.
    I did exactly what the tutorial tell me to do. So can you enlight me and tell what I am doing wrong here.

  • Josh Ziegler Jul 19, 2009 @ 3:38

    psionic: Normally that error comes up if you forget the ‘-p’ option which allows you to supply the password.

    So instead of your error message, you should get this instead:
    error: ‘Access denied for user ‘root’@’localhost’ (using password: YES)’.

  • sisantha Jul 26, 2009 @ 17:36

    I read your valued article and appreciate it very much.
    I did much with FreeBSD and wants to do the same with OpenBSD but only once went with my MySQL and phpMyAdmin (SunSparcII ). After reinstalling, I get problems with phpmyadmin!
    This one “phpMyAdmin – Error :Cannot start session without errors, please check errors given in your PHP and/or web server log file and configure your PHP installation properly.”
    Would you kindly let me know the reason for this pl?
    OpenBSD V 4.5 Sparc64
    Mysql-5.0.77

    Regards,

    Sisantha

    ps., my website is sometime off (constructing)

  • Hendra Feb 11, 2012 @ 7:43

    I tried in VMware, in my machine doesnt have rc.conf.local file. What should I do ?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum