Why does MariaDB installation last for a long time?

Installation of mariaDB lasted for a long time, ending the terminal process.

$ sudo apt-get install mariadb-server mariadb-client

Attempting to install MariaDB again caused the following problems:

Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 31891 (apt-get) - open (11: Resource temporarily unavailable)

So I found the following solution.

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock*

$ sudo dpkg --configure -a
$ sudo apt update

But this also occured some problem:

$ sudo dpkg --configure -a
Setting up mariadb-server-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
^Cdpkg: error processing package mariadb-server-10.3 (--configure):
 installed mariadb-server-10.3 package post-installation script subprocess was interrupted
dpkg: dependency problems prevent configuration of mariadb-server:
 mariadb-server depends on mariadb-server-10.3 (>= 1:10.3.22-0ubuntu0.19.10.1); however:
  Package mariadb-server-10.3 is not configured yet.

dpkg: error processing package mariadb-server (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mariadb-server-10.3
 mariadb-server

I deleted and reinstalled MariaDB, but the installation did not complete for a long time.

$ sudo apt-get install mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server-10.3
  mariadb-server-core-10.3
Suggested packages:
  mailx mariadb-test tinyca
The following NEW packages will be installed:
  mariadb-client mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server
  mariadb-server-10.3 mariadb-server-core-10.3
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/17.3 MB of archives.
After this operation, 158 MB of additional disk space will be used.
Do you want to continue? [Y/n] y 
Preconfiguring packages ...
Selecting previously unselected package mariadb-common.
(Reading database ... 212987 files and directories currently installed.)
Preparing to unpack .../mariadb-common_1%3a10.3.22-0ubuntu0.19.10.1_all.deb ...
Unpacking mariadb-common (1:10.3.22-0ubuntu0.19.10.1) ...
Selecting previously unselected package mariadb-client-core-10.3.
Preparing to unpack .../mariadb-client-core-10.3_1%3a10.3.22-0ubuntu0.19.10.1_amd64.deb ...
Unpacking mariadb-client-core-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Selecting previously unselected package mariadb-client-10.3.
Preparing to unpack .../mariadb-client-10.3_1%3a10.3.22-0ubuntu0.19.10.1_amd64.deb ...
Unpacking mariadb-client-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Selecting previously unselected package mariadb-server-core-10.3.
Preparing to unpack .../mariadb-server-core-10.3_1%3a10.3.22-0ubuntu0.19.10.1_amd64.deb ...
Unpacking mariadb-server-core-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Setting up mariadb-common (1:10.3.22-0ubuntu0.19.10.1) ...
update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mariadb-server-10.3.
(Reading database ... 213145 files and directories currently installed.)
Preparing to unpack .../mariadb-server-10.3_1%3a10.3.22-0ubuntu0.19.10.1_amd64.deb ...
Unpacking mariadb-server-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Selecting previously unselected package mariadb-client.
Preparing to unpack .../mariadb-client_1%3a10.3.22-0ubuntu0.19.10.1_all.deb ...
Unpacking mariadb-client (1:10.3.22-0ubuntu0.19.10.1) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../mariadb-server_1%3a10.3.22-0ubuntu0.19.10.1_all.deb ...
Unpacking mariadb-server (1:10.3.22-0ubuntu0.19.10.1) ...
Setting up mariadb-server-core-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Setting up mariadb-client-core-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Setting up mariadb-client-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Setting up mariadb-server-10.3 (1:10.3.22-0ubuntu0.19.10.1) ...
Created symlink /etc/systemd/system/mysql.service → /lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /lib/systemd/system/mariadb.service.

I'm using ubuntu 20.04 and have same experience.(mariadb-server-10.3)
After all, I update mariadb repository on https://downloads.mariadb.org/mariadb/repositories and install mariadb-server-10.5

[install progress]

  1. Choose a Distro: Ubuntu
  2. Choose a Release: 20.04 "focal" -- in my case
  3. Choose a Version: 10.5 [Stable]
  4. Choose a Mirror: press 'Show All Mirros' button and click 'DigitalOcean - New York, US'
    -- some mirrors does not work, because fetch keys does not valid
  5. Needed progress will be shown below.

    sudo apt-get install software-properties-common
    sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
    sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.5/ubuntu focal main'

    sudo apt update
    sudo apt install mariadb-server

If you had mySQL installed before, and your syslog shows

AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld"

no purging, reinstalling or the like will help when using the stock Ubuntu/Debian repo.

A lingering AppArmor profile will prevent mariaDB from successfully starting.

So effectively anyone who wants to switch from mySQL to mariaDB on Debian or Ubuntu will fail miserably (could it be there is some Oracle maintainer involved in the package creation ? ;-) )

This is known since 18.04, including a fix, and not fixed until now.

https://bugs.launchpad.net/ubuntu/+source/mariadb-10.1/+bug/1806263

echo "/usr/sbin/mysqld { }" > /etc/apparmor.d/usr.sbin.mysqld
apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld

will fix it. Afterwards, mariaDB can be installed and/or the service can be started.