TransWikia.com

Why doesn't MariaDB or MySQL start?

Ask Ubuntu Asked on February 6, 2021

Apparently purging, and/or reinstalling mysql and mariadb can cause conflicts, so tried:

root@mordor:~# 
root@mordor:~# sudo apt purge mariadb-server mariadb-client mysql-client mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client' is not installed, so not removed
Package 'mysql-server' is not installed, so not removed
The following packages will be REMOVED:
  mariadb-client* mariadb-server*
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
After this operation, 20.5 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 181581 files and directories currently installed.)
Removing mariadb-client (1:10.4.17+maria~focal) ...
Removing mariadb-server (1:10.4.17+maria~focal) ...
root@mordor:~# 
root@mordor:~# 
root@mordor:~# rm -rf  /var/lib/mysql
root@mordor:~# 
root@mordor:~# sudo apt install mariadb-client mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mariadb-client mariadb-server
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/6252 B of archives.
After this operation, 20.5 kB of additional disk space will be used.
Selecting previously unselected package mariadb-client.
(Reading database ... 181576 files and directories currently installed.)
Preparing to unpack .../mariadb-client_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-client (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../mariadb-server_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-server (1:10.4.17+maria~focal) ...
Setting up mariadb-client (1:10.4.17+maria~focal) ...
Setting up mariadb-server (1:10.4.17+maria~focal) ...
root@mordor:~# 
root@mordor:~# mariadb
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@mordor:~# 
root@mordor:~# systemctl status mariadb.service
● mariadb.service - MariaDB 10.4.17 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: failed (Result: exit-code) since Sat 2020-11-14 10:43:31 PST; 1h 23min ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 90075 (code=exited, status=1/FAILURE)
     Status: "MariaDB server is down"

Nov 14 10:43:29 mordor systemd[1]: Starting MariaDB 10.4.17 database server...
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Note] /usr/sbin/mysqld (mysqld 10.4.17-MariaDB-1:10.4.17+maria~focal-l>
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Warning] Could not increase number of max_open_files to more than 1638>
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Warning] Changed limits: max_open_files: 16384  max_connections: 500 (>
Nov 14 10:43:31 mordor systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Nov 14 10:43:31 mordor systemd[1]: mariadb.service: Failed with result 'exit-code'.
Nov 14 10:43:31 mordor systemd[1]: Failed to start MariaDB 10.4.17 database server.
root@mordor:~# 

How do I start mariadb? I can purge it again, but that’s just a loop.

2 Answers

can at least get into the db:

root@mordor:~# 
root@mordor:~# sudo apt purge mariadb-server-core-10.4 mariadb-server-10.4 mariadb-client-core-10.4  mariadb-client-10.4 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mariadb-client-10.4' is not installed, so not removed
Package 'mariadb-client-core-10.4' is not installed, so not removed
Package 'mariadb-server-10.4' is not installed, so not removed
Package 'mariadb-server-core-10.4' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  galera-4 libdbd-mysql-perl libdbi-perl libterm-readkey-perl socat
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
root@mordor:~# 
root@mordor:~# sudo apt purge mysql-server-core-8.0 mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client-8.0' is not installed, so not removed
Package 'mysql-client-core-8.0' is not installed, so not removed
Package 'mysql-server-8.0' is not installed, so not removed
Package 'mysql-server-core-8.0' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  galera-4 libdbd-mysql-perl libdbi-perl libterm-readkey-perl socat
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
root@mordor:~# 
root@mordor:~# rm -rf  /var/lib/mysql
root@mordor:~# 
root@mordor:~# sudo apt install mariadb-client mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  mariadb-client-10.4 mariadb-client-core-10.4 mariadb-server-10.4 mariadb-server-core-10.4
Suggested packages:
  mailx mariadb-test tinyca
The following NEW packages will be installed:
  mariadb-client mariadb-client-10.4 mariadb-client-core-10.4 mariadb-server mariadb-server-10.4 mariadb-server-core-10.4
0 upgraded, 6 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/12.9 MB of archives.
After this operation, 142 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Preconfiguring packages ...
Selecting previously unselected package mariadb-client-core-10.4.
(Reading database ... 181260 files and directories currently installed.)
Preparing to unpack .../0-mariadb-client-core-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
Unpacking mariadb-client-core-10.4 (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-client-10.4.
Preparing to unpack .../1-mariadb-client-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
Unpacking mariadb-client-10.4 (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-server-core-10.4.
Preparing to unpack .../2-mariadb-server-core-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
Unpacking mariadb-server-core-10.4 (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-server-10.4.
Preparing to unpack .../3-mariadb-server-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
Unpacking mariadb-server-10.4 (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-client.
Preparing to unpack .../4-mariadb-client_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-client (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../5-mariadb-server_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-server (1:10.4.17+maria~focal) ...
Setting up mariadb-server-core-10.4 (1:10.4.17+maria~focal) ...
Setting up mariadb-client-core-10.4 (1:10.4.17+maria~focal) ...
Setting up mariadb-client-10.4 (1:10.4.17+maria~focal) ...
Setting up mariadb-client (1:10.4.17+maria~focal) ...
Setting up mariadb-server-10.4 (1:10.4.17+maria~focal) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
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.
Setting up mariadb-server (1:10.4.17+maria~focal) ...
Processing triggers for man-db (2.9.1-1) ...
root@mordor:~# 
root@mordor:~# sudo 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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the 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]  
 ... 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] 
 ... 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] 
 - 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] 
 ... 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@mordor:~# 
root@mordor:~# mariadb -u root
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 57
Server version: 10.4.17-MariaDB-1:10.4.17+maria~focal-log mariadb.org binary distribution

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)]> exit
Bye
root@mordor:~# 

or as a regular user:

nicholas@mordor:~$ 
nicholas@mordor:~$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 60
Server version: 10.4.17-MariaDB-1:10.4.17+maria~focal-log mariadb.org binary distribution

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)]> 
MariaDB [(none)]> exit
Bye
nicholas@mordor:~$ 

Answered by Nicholas Saunders on February 6, 2021

1st check if mariadb is running. You can not connect to it if it is not.

You forgot to do

sudo mysql_secure_installation

to set up a user and password.

Regarding this command please also ...

  • remove the anonymous user
  • remove the test database
  • disallow root login remotely

Generally you can do it like this too:

sudo -i
{admin password}
mariadb

and then set up a user and a password. Try to avoid using common names as a user (ie. no root, admin, your user name etc) and use a personal username. It makes it 1 more thing someone needs to guess.

Answered by Rinzwind on February 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP