How to Solve Error Message Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.

Posted on

Introduction

This is an article where the main focus is exist in the title of this article. Actually, this article is a continuation from the previous article. The previous article has a title of ‘How to Solve Error Message Problem: problem with installed package mysql-server when Installing MariaDB Server in Linux CentOS 8’ in this link. So, the error exist after the installation of MariaDB database server to replace MySQL database server. Upon the execution of MariaDB service to start, the following error message appear :

[root@10 ~]# systemctl start mariadb
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
[root@10 ~]# journalctl -xe
-- Unit dnf-makecache.service has begun starting up.
Mar 19 21:09:25 10.0.2.15 dnf[2617]: Metadata cache refreshed recently.
Mar 19 21:09:25 10.0.2.15 systemd[1]: dnf-makecache.service: Succeeded.
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The unit dnf-makecache.service has successfully entered the 'dead' state.
Mar 19 21:09:25 10.0.2.15 systemd[1]: Started dnf makecache.
-- Subject: Unit dnf-makecache.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit dnf-makecache.service has finished starting up.
--
-- The start-up result is done.
Mar 19 21:43:44 10.0.2.15 systemd[1]: Starting MariaDB 10.3 database server...
-- Subject: Unit mariadb.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mariadb.service has begun starting up.
Mar 19 21:43:44 10.0.2.15 mysql-prepare-db-dir[2651]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Mar 19 21:43:44 10.0.2.15 mysql-prepare-db-dir[2651]: If this is not the case, make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.
Mar 19 21:43:44 10.0.2.15 mysqld[2689]: 2021-03-19 21:43:44 0 [Note] /usr/libexec/mysqld (mysqld 10.3.27-MariaDB) starting as process 2689 ...
Mar 19 21:43:45 10.0.2.15 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Mar 19 21:43:45 10.0.2.15 systemd[1]: mariadb.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The unit mariadb.service has entered the 'failed' state with result 'exit-code'.
Mar 19 21:43:45 10.0.2.15 systemd[1]: Failed to start MariaDB 10.3 database server.
-- Subject: Unit mariadb.service has failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mariadb.service has failed.
--
-- The result is failed.
[root@10 ~]#

So, after reviewing the error message upon executing the command ‘journalctl -xe’ after failing to start MariaDB database server, check the status of the MariaDB database server. Execute the following command to preview it :

[root@10 mysql]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2021-03-19 19:52:52 EDT; 6s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 2319 ExecStart=/usr/libexec/mysqld --basedir=/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER (code=exited, status=1/FAILURE)
  Process: 2281 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
  Process: 2257 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 2319 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"

Mar 19 19:52:51 10.0.2.15 systemd[1]: Starting MariaDB 10.3 database server...
Mar 19 19:52:51 10.0.2.15 mysql-prepare-db-dir[2281]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Mar 19 19:52:51 10.0.2.15 mysql-prepare-db-dir[2281]: If this is not the case, make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.
Mar 19 19:52:51 10.0.2.15 mysqld[2319]: 2021-03-19 19:52:51 0 [Note] /usr/libexec/mysqld (mysqld 10.3.27-MariaDB) starting as process 2319 ...
Mar 19 19:52:52 10.0.2.15 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Mar 19 19:52:52 10.0.2.15 systemd[1]: mariadb.service: Failed with result 'exit-code'.
Mar 19 19:52:52 10.0.2.15 systemd[1]: Failed to start MariaDB 10.3 database server.
[root@10 mysql]#

Solution to solve the problem

So, according to the article in this link with the title of ‘How to Solve Error Message Problem: problem with installed package mysql-server when Installing MariaDB Server in Linux CentOS 8’ in this link and also the explanation in the previous part, MariaDB is inactive. Actually, the last resort is to move the content in the ‘/var/lib/mysql’. Before moving the content of it, just becareful if there are already lots of data available. This step for some reason in this article is not recommended. But by moving it, MariaDB is able to start after the installation. The folllowing is the execution of it :

1. First of all, make sure MySQL package is not running and it is not even exist. After that access ‘/var/lib/mysql’ folder as follows :

[root@10 ~]# cd /var/lib/mysql/
[root@10 mysql]# ls
 aria_log.00000001   binlog.index      client-key.pem       ib_buffer_pool  '#innodb_temp'        performance_schema   server-key.pem
 aria_log_control    ca-key.pem        db_guest_machine     ibdata1          mysql                private_key.pem      sys
 auto.cnf            ca.pem           '#ib_16384_0.dblwr'   ib_logfile0      mysql.ibd            public_key.pem       undo_001
 binlog.000001       client-cert.pem  '#ib_16384_1.dblwr'   ib_logfile1      mysql_upgrade_info   server-cert.pem      undo_002
[root@10 mysql]# mkdir temp

2. Move all of the content inside of /var/lib/mysql to a certain variable. For an example ‘temp’ as in the creation of it above. In this context, to clear all of the content, just move ‘/var/lib/mysql/temp’ to another path. For an example, it is a certain folder and path, such as ‘/root’.

[root@10 mysql]# mv * temp/
mv: cannot move 'temp' to a subdirectory of itself, 'temp/temp'
[root@10 mysql]# ls -al
total 8
drwxr-xr-x.  3 mysql mysql   18 Mar 19 21:51 .
drwxr-xr-x. 39 root  root  4096 Mar 18 23:47 ..
drwxr-xr-x   7 root  root  4096 Mar 19 21:51 temp
[root@10 mysql]# mv temp/ /root/temp/mysql-temp
[root@10 mysql]# cd ..
[root@10 lib]# chown -Rv mysql.mysql /var/lib/mysql/
ownership of '/var/lib/mysql/' retained as mysql:mysql
[root@10 lib]#

3. Next, start the MariaDB service and soon after check ‘/var/lib/mysql’ folder’s content as in the following command execution :

[root@10 lib]# systemctl start mariadb
[root@10 lib]# cd /var/lib/mysql/
[root@10 mysql]# ls
aria_log.00000001  ib_buffer_pool  ib_logfile0  ibtmp1             mysql       mysql_upgrade_info  tc.log
aria_log_control   ibdata1         ib_logfile1  multi-master.info  mysql.sock  performance_schema
[root@10 mysql]#

As in the above output, starting MariaDB service is a success. Moreover, there are generated content after starting MariaDB service in ‘/var/lib/sql’.

4. Do not forget to start the command for securing MariaDB as follows :

[root@10 mysql]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@10 mysql]# mysql_secure_installation

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!
[root@10 mysql]#

5. Finally, try to access MariaDB database server’s service as follows :

[root@10 mysql]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.27-MariaDB MariaDB Server

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)]>

One thought on “How to Solve Error Message Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.

Leave a Reply