These installation instructions are for MySQL installation, the process to install MariaDB is analogous.

1 Installation

Download and install the package:

Copy
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

Complete installation removing a previous version and its databases

If there is a previous installation of MySQL and you do not need this data you can do a entirely installation by removing the current data. This action deletes all data and previous databases, use only in case you are completily sure that the current data is no longer needed.

Copy
## [ONLY FOR EXPERTS ADMINISTRATORS] rm -rf /var/lib/mysql*

Ensure the repo is enabled and install mysql-community-server:

Copy
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
yum -y --enablerepo=mysql80-community install mysql-community-server

1.1 Set db and table names case insensitive

To make all database and table names case insensitive, lower_case_table_names must be set to 1.

To do that, the following text nust be added to /etc/my.cnf or /etc/my.cnf.d/mysqld.cnf under [mysqld].

Copy
[mysqld]
lower_case_table_names=1

Set option before mysql initilization

This option must be set before iniitializing mysql for the first time.

If the option is modified afterwards, the next mysqld service start will fail.

2 Enable and start service

Copy
systemctl enable mysqld.service
systemctl start mysqld.service

Now the service must be up&running:

Copy
# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-01-13 16:32:06 CET; 4min 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 25083 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 25205 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─25205 /usr/sbin/mysqld

Jan 13 16:31:55 pmultidb systemd[1]: Starting MySQL Server...
Jan 13 16:32:06 pmultidb systemd[1]: Started MySQL Server.

3 Set root password

A password for root user is automatically generated, you can find it in the /var/log/mysql/mysqld.log file:

Copy
grep "A temporary password" /var/log/mysql/mysqld.log

To change it execute:

Copy
mysql_secure_installation

To execute mysql and manage databases you can use:

Copy
mysql -u root -p

4 Allow connections on all interfaces on MariaDB

Edit file /etc/my.cnf.d/mariadb-server.cnf to accept connections on all interfaces and not only on localhost.

Copy
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0

Restart the service:

Copy
systemctl restart mariadb.service

5 Allow remote connections (user for JDBC Connections)

Remote connections error

If remote connections are not allowed the following messages will appears when you try to connect from another server using the IP and port.

Copy
Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL/MariaDB server

MySQL JDBC is only able to connect via TCP/IP (on Unix, or TCP/IP or named pipe on Windows). The MySQL JDBC driver cannot establish a connection using the local unix socket.With MySQL on Unix, localhost has a different meaning that we might expect. It is not a hostname synonym for the 127.0.0.1 TCP/IP loopback address. On Unix, MySQL user.

Copy
'user1'@'localhost'

specifies a user that can connect only via unix socket file; it's not possible to connect to that user via TCP/IP.

You can use this sentence to create user and stablish TCP/IP connections to the database server:

Copy
mysql
Copy
mysql> CREATE USER 'deister' IDENTIFIED BY 'XXio98$1234';
Query OK, 0 rows affected (0.01 sec)
Copy
mysql> GRANT ALL PRIVILEGES ON *.* TO 'deister';
Query OK, 0 rows affected (0.03 sec)

This instruction creates a user "deister" with full privileges and you can use it to make JDBC connection via TCP/IP.

Permissions

This command grants the user all permissions. However, you can grant specific permissions to maintain precise control over database access. For example, to explicitly grant the SELECT permission, you would use the following command:
Copy
GRANT SELECT ON *.* TO 'username';

6 Create database

To log in to MySQL as the user you just created, type the following command. Replace username with the name of the user you created in previous step.

Copy
mysql -u username -p

Type the user's password, and then press Enter.

To create a database, type the following command. Replace dbname with the name of the database that you want to create:

Copy
CREATE DATABASE dbname;

To work with the new database, type the following command. Replace dbname with the name of the database you created before:

Copy
USE dbname;

7 Import a database

The database must be exists if not, create it before:

Copy
CREATE DATABASE dbname;

Then use this instruction to import a database from file:

Copy
mysql -u deister -p dbname < dbname.sql