31

I am running Arch Linux 4.8.4-1 on a 64bit installation. I installed MariaDB via pacman. When I try to start it with systemctl start mysqld, it gives me

Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.

The output of systemctl status mariadb.service is

● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2016-11-02 16:55:12 IST; 3min 6s ago
  Process: 5123 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
  Process: 5070 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set
  Process: 5067 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 5123 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"

Nov 02 16:55:11 pranav-laptop systemd[1]: Starting MariaDB database server...
Nov 02 16:55:12 pranav-laptop mysqld[5123]: 2016-11-02 16:55:12 140082509282496 [Note] /usr/sbin/mysqld (mysqld 10.1.18-MariaDB) starting as process 5
Nov 02 16:55:12 pranav-laptop mysqld[5123]: 2016-11-02 16:55:12 140082509282496 [Warning] Can't create test file /var/lib/mysql/pranav-laptop.lower-te
Nov 02 16:55:12 pranav-laptop mysqld[5123]: [90B blob data]
Nov 02 16:55:12 pranav-laptop systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Nov 02 16:55:12 pranav-laptop systemd[1]: Failed to start MariaDB database server.
Nov 02 16:55:12 pranav-laptop systemd[1]: mariadb.service: Unit entered failed state.
Nov 02 16:55:12 pranav-laptop systemd[1]: mariadb.service: Failed with result 'exit-code'.

If I need to post anything else, let me know...

UPDATE: After trying Jérémy Munoz's comment, mysql still doesn't start, but I get a different systemctl status mariadb.service

● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2016-11-02 21:03:24 IST; 4min 7s ago
  Process: 14350 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
  Process: 14296 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl se
  Process: 14294 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 14350 (code=exited, status=1/FAILURE)

Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412958252224 [ERROR] Could not open mysql.plugin table. Some plugins may be not lo
Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412958235392 [Warning] Failed to load slave replication state from table mysql.gti
Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412362684160 [Note] InnoDB: Dumping buffer pool(s) not yet started
Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412958252224 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' d
Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412958252224 [Note] Server socket created on IP: '::'.
Nov 02 21:03:24 pranav-laptop mysqld[14350]: 2016-11-02 21:03:24 140412958252224 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mys
Nov 02 21:03:24 pranav-laptop systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Nov 02 21:03:24 pranav-laptop systemd[1]: Failed to start MariaDB database server.
Nov 02 21:03:24 pranav-laptop systemd[1]: mariadb.service: Unit entered failed state.
Nov 02 21:03:24 pranav-laptop systemd[1]: mariadb.service: Failed with result 'exit-code'.

UPDATE: After running mysql_install_db, I get this error:

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to either run 'make install' to
copy the software into the correct location ready for operation.
If you don't want to do a full install, you can use the --srcddir
option to only install the mysql database and privilege tables

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

The latest information about mysql_install_db is available at
https://mariadb.com/kb/en/installing-system-tables-mysql_install_db

/etc/mysql/my.cnf

8
  • You seem lacking permissions to /var/lib/mysql/ Nov 2, 2016 at 12:14
  • Which permissions should I set? Nov 2, 2016 at 12:43
  • chown -R mysql. /var/lib/mysql/ Nov 2, 2016 at 14:08
  • @JérémyMunoz I tried your solution. It still doesn't start. I updated the question with the new error. Nov 2, 2016 at 15:40
  • Please show your mysql/mariadb config from file /etc/mysql/my.cnf. Nov 3, 2016 at 15:48

6 Answers 6

41

If you haven't any real data in your database then clear all in /var/lib/mysql.

After that try again to run command mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql to initialize database directory.

The newer command for mariadb is mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql.

5
  • 1
    what's the methodology of this answer?
    – kittygirl
    Oct 15, 2018 at 14:10
  • is there anything else to try if this doesnt work?
    – moeiscool
    Feb 8, 2019 at 19:25
  • @kittygirl Hi, the objective of this is to recreate MySQL's data structure, either because it got messed up or because it didn't exist to being with. Or at least, that's how I understand it. Mar 11, 2019 at 16:34
  • 1
    This works especially if you had mysql and then purged it. Installing madiadb after that causes the error, and this fixes it.
    – marw
    Apr 7, 2020 at 21:27
  • 1
    What if I have data? after that commands if I copy back folder inside /var/lib/mysql, databases will be back? I mean, I download folders from "/var/lib/mysql" to my computer then do these steps and finally upload folders to get back databases. is this correct?
    – hamid
    Aug 4, 2022 at 5:21
10
cd /var/lib/mysql
ls
rm -r *
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
systemctl start mysqld
systemctl start mysql.service
systemctl start mariadb
mysql

Then it works just fine

3
  • 1
    This worked for me! Kudos!
    – FoulFoot
    Jan 29, 2021 at 3:20
  • This solution work for me, Thanks bro. Jun 28, 2021 at 8:06
  • This didn't worked for me: # mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql ... >You can start the MariaDB daemon with: >cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql' ... # systemctl start mysqld >Failed to start mysqld.service: Unit not found. Apr 19, 2022 at 19:05
7

You need to run mysql_install_db to initialize MySQL data directory.

0
5

Faced same problem. This got resolved after following below steps:

  1. Uninstalled the mariadb maridb-server packages
  2. Removed the directory /var/lib/mysql.
  3. Reinstalled the Mariadb, Mariadb-server packages.
  4. systemct start mariadb; systemctl enable mariadb

(problem solved).

0
2

I had same problem on Ubuntu 18.04m packages registered seem unable to start or else...

I resolved by adding correct package list and signature from the this site.

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mariadb.mirrors.ovh.net/MariaDB/repo/10.3/ubuntu bionic main'
sudo apt update
sudo apt install mariadb-server

et voila..

2
  • Hmm, that's interesting... So you had a problem with the installation to begin with? Linux thought it was installed when it really wasn't? That's really weird... For me what ended up happening was that my setup process didn't complete, so I had to manually do the mysql_install_db thing. Mar 11, 2019 at 16:32
  • this worked for me Jan 19, 2020 at 6:58
0

If I can help people who didn't solve their problem with the solutions above :

I also had this problem and it came from a bad configuration in a config file in this repertory : /etc/apache2/sites-available/

So check the config files to see if there isn't a script error.

1
  • 2
    How exactly is a misconfiguration in Apache going to result in MariaDB being unable to start?
    – womble
    Mar 7, 2020 at 5:47

Not the answer you're looking for? Browse other questions tagged .