Skip to content

!!Mariadb Installation and Basic commands

MariaDB is a replacement for Oracle MySQL servers. It is a multithreaded SQL database with a command syntax very similar to mSQL. This page shows how to install MariaDB server on OpenBSD.

!!!There are two packages

mariadb-server – The MariaDB server.

mariadb-client – The client side of MariaDB server including mysqlclient library and headers for the MariaDB client API.

We will only install and mariadb-server

$ doas pkg_add curl
$ doas pkg_add mariabd-server

curl is a one of the dependency package for mariadb-server.

Now we need to configure mariadb to run.

open open /etc/my.cnf with your regular editor

$ vi open /etc/my.cnf

Uncommnet the bold lines

[client-server]

socket=/var/run/mysql/mysql.sock

change the above line to

socket=/var/www/var/run/mysql/mysql.sock

port=3306

bind-address=0.0.0.0

data=/var/mysql

save

Run the following command

$ mysql_install_db

!!!Initialize MariaDB data directory

The above command is for initialising You need to run mysql_install_db command. It initialises the MariaDB data directory and creates the system tables:

$ mysql_install_db

Now start mariadb

$ doas rcctl enable mysqld
$ doas rcctl start mysqld
mysqld(ok)

To check if you mariadb is running run following command

$ ps -aux | grep mysqld

you will see a line pops up as follow:

root     94120  0.0  0.2  1016  1040 p0  Sp     10:40AM    0:00.02 /bin/sh /usr/local/bin/mysqld_safe

We are good to go..its running

!!Mariadb database creation and user privileges commands

To connect to mariadb console

$ mysql -u root -p

Create a new database:

MariaDB> create database DATABASE_NAME;

Create a new user (only with local access) and grant privileges to this user on the new database:

MariaDB> grant all privileges on DATABASE_NAME.* TO 'USER_NAME'@'localhost' identified by 'PASSWORD';

Create a new user (with remote access) and grant privileges to this user

on the new database:

MariaDB> grant all privileges on DATABASE_NAME.* TO 'USER_NAME'@'%25' identified by 'PASSWORD';

After modifying the MariaDB grant tables, execute the following command in order to apply the changes:

MariaDB> flush privileges;

other command to add user :

CREATE USER 'user1'@localhost IDENTIFIED BY 'password1'; database list: SHOW DATABASES; grant access : GRANT ALL PRIVILEGES ON 'yourDB'.* TO 'user1'@localhost;

{-No Error Happy days-} =)