From Fedora Project Wiki

No edit summary
m (typo)
Line 1: Line 1:
MariaDB is a dropin replacement of MySQL, forked by the community from the latter.
MariaDB is a drop-in replacement of MySQL, forked by the community from the latter.


== Installation ==
== Installation ==

Revision as of 16:19, 19 February 2020

MariaDB is a drop-in replacement of MySQL, forked by the community from the latter.

Installation

$ su - root
$ dnf install mariadb mariadb-server

Initial setup

First let's start MariaDB

$ systemctl start mariadb

Now start the secure installation assistant

$ mysql_secure_installation

Press enter if you didn't have setup a password previously

Then it is advisable to answer as follows

Set root password? [Y/n] Y
Do not use system's root account password
Do not provide the system administrator's password for your Linux system here. Use a different strong password, since this is a separate authentication for a MySQL user called "root."
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

To start MariaDB on boot

$ systemctl enable mariadb

GUI frontends

There are some popular frontends such as phpMyAdmin

Default installation and configuration files

The configuration files are stored in the /etc/my.cnf.d/ directory and the main configuration file is /etc/my.cnf

The default log file is /var/log/mariadb/mariadb.log

The default installation directory is /var/lib/mysql

The default PID file is /var/run/mariadb/mariadb.pid

The default unix socket file is /var/lib/mysql/mysql.sock

Firewall

MariaDB operates on port 3306 (or whatever else you set in your my.cnf). In firewalld you can open it like this:

$ # make it last after reboot
$ firewall-cmd --permanent --add-port=3306/tcp
$ # change runtime configuration
$ firewall-cmd --add-port=3306/tcp

In case of iptables:

$ iptables -A INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

Bear in mind that you probably don't want to open your database server to the whole world.

User Creation and Database Creation

Soon you run into need of creating a user (and database for the user). By default, root user has no password, unless you set it before, e.g. using mysql_secure_installation:

$ mysql -uroot -p

This will run the mysql interactive shell under root user, so we can create a database and a user that will have access to this database:

$ mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.16-MariaDB MariaDB Server

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

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

MariaDB [(none)]> CREATE DATABASE mydb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'john'@'localhost' IDENTIFIED BY 'abcdefgh';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON mydb.* TO 'john'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

Now we can verify that the user has access to the database by creating some table and fill it with some data:

$ mysql -ujohn -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.1.16-MariaDB MariaDB Server

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

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

MariaDB [(none)]> CREATE TABLE mydb.t1 (numb int);
Query OK, 0 rows affected (0.09 sec)

MariaDB [(none)]> INSERT INTO mydb.t1 VALUES (1), (2);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0