Centos – Unable to start MySQL on CentOS

centosMySQL

I've just installed a fresh version of MySQL on my CentOS machine. The problem I'm facing is that when I run this command:

# service mysqld start

I get in the console this error message:

[ERROR] Can't change data directory owner to mysql

I'm not exactly sure what it means and how to fix it. Any comments and solutions are welcome. Thanks!

EDIT

It seems like I've fixed it with:

chown -R mysql /var/lib/mysql

But the very same command # service mysqld start now leads to another error message:

[ERROR] –initialize specified but the data directory has files in it. Aborting

Indeed, it has files, because during installation CentOS itself created this folder /var/lib/mysql and put some files in it. I did not do anything manually. So, what the heck is going on with CentOS and how to fix it?? Thanks!!

EDIT

It seems like either MySQL or CentOS has gone crazy. The catch is, if I delete all files from data directory, on start-up (when I run #service mysqld start) it creates a bunch of files in it, like ca-key.pem and other .pem files. So, it creates files and then throws an error, that the data directory is not empty. What a stupid behaviour! But how can I solve all this???

Best Answer

I had a similar issue with Kubernetes and MySQL 5.7 as well.

Adding the suggestion from yosifki to my container's definition got things working.

A new ext4 disk partition is not usually empty; there is a lost+found directory, which mysql is known to choke on. You could try adding --ignore-db-dir=lost+found to the CMD to know for sure (from mysql docs)

Here's an extract of my working YAML definition:

name: mysql-master
image: mysql:5.7
args:
  - "--ignore-db-dir=lost+found"

Here's an example snippet in docker-compose to clarify:

version: '3'
services:
  mysql-master:
    image: mysql:5.7
    command: [--ignore-db-dir=lost+found]
    environment:
      - MYSQL_ROOT_PASSWORD=root