15

I'm setting up a replication server and when I try to start the mysql service for the first time, it fails:

[root@ravioli mysql]# service mysqld start
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]
[root@ravioli mysql]# tail /var/log/mysqld.log 
151013 13:41:27 [ERROR] Plugin 'InnoDB' init function returned error.
151013 13:41:27 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
/usr/libexec/mysqld: File '/databases/mysql/mysql_slow_queries.log' not found (Errcode: 13)
151013 13:41:27 [ERROR] Could not use /databases/mysql/mysql_slow_queries.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
151013 13:41:27 [ERROR] Unknown/unsupported storage engine: InnoDB
151013 13:41:27 [ERROR] Aborting

151013 13:41:27 [Note] /usr/libexec/mysqld: Shutdown complete

151013 13:41:27 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

I confirmed that user mysql sees and is able to write to /databases/mysql/mysql_slow_queries.log.

Then I checked getenforce and see it is set to Enforcing.

How do I configure MySQL to play nicely with SELinux?

3 Answers 3

42

All I needed was to delete two files which are:

ib_logfile0

and

ib_logfile1

Then going back to start mysql everything worked

5
  • 1
    For anyone using homebrew on a mac, I found the location of these files at /usr/local/var/mysql/ib_logfile0 and /usr/local/var/mysql/ib_logfile1. Removing them resolved the problem.
    – user101289
    Jan 18, 2021 at 5:47
  • 3
    I also had to delete ibdata1 file and directory performance_schema
    – Sathish
    May 26, 2021 at 10:59
  • Great thanks. This solved my problem. But I am at local development I don't can for any data lose Apr 15, 2022 at 8:11
  • Up for this. This one solved my problem.
    – JustAce
    Nov 6, 2022 at 22:52
  • 1
    This is the most dangerous upvoted answer I've seen. I guess the users that loose their data by following bad answers like this and ASSUME every Innodb error is corruption don't come back here to comment/down vote. Read the error message people. Even if you don't, copy the log files and don't remove them so at least you can go back when you realise how broken this answer is. @a-coder did read, and gave a beautiful self answer to the actual problem, without destroying their data.
    – danblack
    Nov 14, 2022 at 22:29
5

This resolved my problem:

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

sudo rm /var/lib/mysql/ib_logfile0
sudo rm /var/lib/mysql/ib_logfile1

sudo apt-get install mysql-server
3
  • 2
    Perhaps the second autoremove should be autoclean?
    – Buffalo
    Jul 31, 2018 at 11:07
  • 1
    You are correct. Updated the answer.
    – Anders B
    Feb 23, 2022 at 20:18
  • As commented above, this answer is dangerous. The OP wanted their slow query log on /databases/mysql/, purging our their config and installing doesn't acheive this. Also, they where using Centos, not a ubuntu/debian, so obviously apt is the wrong answer.
    – danblack
    Nov 14, 2022 at 22:31
1

Ok this was actually much easier than expected.

By default SELinux is Enforcing, which prevents unexpected writes on the filesystem. I just needed to tell SELinux that it's OK for MySQL to write to a non-standard directory. To wit:

[root@ravioli]# semanage fcontext -a -t mysqld_db_t "/databases/mysql(/.*)?"
-bash: semanage: command not found.

Derp. To install semanage, use this:

yum install policycoreutils-python

Now run the command again. This may take a few moments...

[root@ravioli]# semanage fcontext -a -t mysqld_db_t "/databases/mysql(/.*)?"

Check to see that SELinux is configured for this new directory by looking at this config file:

[root@ravioli]#  grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local

/databases/mysql(/.*)?    system_u:object_r:mysqld_db_t:s0

Additional directories can be added, for instance if you have a dedicated tmp directory somewhere.

[root@ravioli]# semanage fcontext -a -t mysqld_db_t "/databases/mysql_tmp(/.*)?"

Check the config again:

[root@ravioli]# grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local

/databases/mysql(/.*)?    system_u:object_r:mysqld_db_t:s0
/databases/mysql_tmp(/.*)?    system_u:object_r:mysqld_db_t:s0

Finally, update the permissions using restorecron

restorecon -R -v /www/databases/mysql/

and in my setup,

restorecon -R -v /www/databases/mysql_tmp/

Now issue:

service mysqld start

Bene.

Starting mysqld:         [  OK  ]

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.