How to install MariaDB on NetBSD?


NetBSD is a UNIX-like operating system with a focus on security, simplicity, elegance and clean source code, it is highly portable and robust.

MariaDB is a RDBMS created from MySQL 5.1 source code by the original MySQL developers and designed as a direct and improved MySQL replacement. MariaDB is fast, scalable, and robust, with a rich ecosystem of storage engines, plugins, and other tools that make it versatile and flexible in different scenarios.

MariaDB is available on the official NetBSD repositories then we can install it using the pkgin package manager.

You might also like:

Install

# pkgin install mariadb-server 
calculating dependencies...done.

3 packages to install:
  mariadb-server-5.5.67nb4 perl-5.32.1 mariadb-client-5.5.67nb1

0 to refresh, 0 to upgrade, 3 to install
125M to download, 832M to install

proceed ? [Y/n]

Handle the service

In this section we learn how to start, restart and stop the mysqld service, for this task we are going to use the excelent tools: init, rc and service.

Add init script

The mariadb-server package provides us an example script located under /usr/pkg/share/examples/rc.d/mysqld and we can use it as our init script copying it to /etc/rc.d.

# cp -v /usr/pkg/share/examples/rc.d/mysqld /etc/rc.d/mysqld
/usr/pkg/share/examples/rc.d/mysqld -> /etc/rc.d/mysqld

Automatic start

I love how *BSD handle services automatic start, simply add to the /etc/rc.conf file this line:

mysqld=YES

The above line instructs to the init system that the mysqld will start automatically after a system reboot.

Check status

# service mysqld status 
mysqld is not running.

start

# service mysqld start  
Initializing MySQL database system tables.
Installing MariaDB/MySQL system tables in '/var/mariadb' ...
210501 18:11:26 [Note] /usr/pkg/sbin/mysqld (mysqld 5.5.67-MariaDB) starting as process 8874 ...
OK
Filling help tables...
210501 18:11:27 [Note] /usr/pkg/sbin/mysqld (mysqld 5.5.67-MariaDB) starting as process 8845 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/pkg/sbin/mysqladmin' -u root password 'new-password'
'/usr/pkg/sbin/mysqladmin' -u root -h myserver.name 'new-password'

Alternatively you can run:
'/usr/pkg/sbin/mysql_secure_installation'
...

Check the status again:

# service mysqld status
mysqld is running as pid 9258.

Restart

Every time you change the configurations files you must reload the changes with:

# service mysqld restart                  
Stopping mysqld.
Starting mysqld.

Stop

# service mysqld stop
Stopping mysqld.

Improvin basic security

mariadb_secure_installation (https://mariadb.com/kb/en/mysql_secure_installation/) is a shell script available on Unix systems, and enables you to improve the security of your MariaDB installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database, which by default can be accessed by anonymous users.
# mysql_secure_installation  
/usr/pkg/bin/mysql_secure_installation: find_mysql_client: not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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 MariaDB
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 MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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
 ... 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, MariaDB 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!

Connect

Now we can connect to the server using the root user and the password provided in the previous step.

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.67-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 
YouTube video

Administering MySQL from the command line, 5 (15)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.