Solution to the problem that mysql cannot start after modifying the default path of the database

Solution to the problem that mysql cannot start after modifying the default path of the database

Preface

When mysql modified the default database path, the service could not be started. After checking the log, it was found that there was an error in the file permission.

For the changed directory, mysql has been set as the owner of the directory! And everything is normal if you start the database directly from the command line.

I used the almighty Google and finally found the reason in a post from a foreigner - SELINUX policy issue!

All background services need to have corresponding permissions for the corresponding directories, and the default path of mysql /var/lib/mysql has added corresponding policies. After the path is modified, due to the lack of corresponding policies, the background process is blocked from reading files by selinux, resulting in permission errors!

Here’s how:

mysql, the method is:

chcon -R -t mysqld_db_t /db/mysql

If it is APACHE, the method is:

# chcon -R -h -t httpd_sys_content_t /www/web/

Attached chcon command help

chcon command: Modify the security context of an object (file) (such as: user: role: type: security level).

Command format:

Chcon [OPTIONS…] CONTEXT FILES…..
Chcon [OPTIONS…] –reference=PEF_FILES FILES

illustrate:

CONTEXT is the security context to be set

FILES Object (Files)

--reference reference object

PEF_FILES Refer to file context

The FILES application refers to the files context as my context.

OPTIONS are as follows:

-f Force execution

-R Recursively modify the security context of an object

-r ROLE Modify the configuration of the security context role

-t TYPE Modify the configuration of the security context type

-u USER Modify the configuration of the security context user

-v displays verbose information

-l, --range=RANGE Change the security level in the security context

mysql, the method is:

chcon -R -t mysqld_db_t /db/mysql

Examples

If you want to share this ftp to anonymous users, you need to enable the following:

chcon -R -t public_content_t /var/ftp

If you want to allow uploading files to the FTP directory you set, SELINUX needs to be set:

chcon -t public_content_rw_t /var/ftp/incoming

Allow users to access their home directory via HTTP. This setting is limited to the user's home directory home page:

setsebool -P httpd_enable_homedirs 1 chcon -R -t httpd_sys_content_t ~user/public_html

If you want to share the samba directory with other users, you need to set:

chcon -t samba_share_t /directory

When sharing the rsync directory:

chcon -t public_content_t /directories

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the error problem when setting the default value of 0000-00-00 in the date and datetime types of Mysql database
  • Example of how to change the default database to mysql in Django
  • Detailed explanation of the role of the default database after MySQL installation

<<:  The best way to automatically mount shared directories on Ubuntu 16.04 startup under Virtualbox

>>:  vue+springboot realizes login verification code

Recommend

How to use .htaccess to prohibit a certain IP from accessing the website

Preface For cost considerations, most webmasters ...

Samba server configuration under Centos7 (actual combat)

Samba Overview Samba is a free software that impl...

CSS implements the web component function of sliding the message panel

Hello everyone, I wonder if you have the same con...

MySQL DML language operation example

Additional explanation, foreign keys: Do not use ...

Java example code to generate random characters

Sample code: import java.util.Random; import java...

Summary of Vue's common APIs and advanced APIs

Table of contents nextTick Mixins $forceUpdate se...

Solution to the problem that elements with negative z-index cannot be clicked

I was working on a pop-up ad recently. Since the d...

Example of using swiper plugin to implement carousel in Vue

Table of contents vue - Use swiper plugin to impl...

Detailed explanation of how to configure openGauss database in docker

For Windows User Using openGauss in Docker Pull t...

Detailed explanation of CSS label mode display property

The code looks like this: <!DOCTYPE html> &...

Summary of the most commonly used knowledge points about ES6 new features

Table of contents 1. Keywords 2. Deconstruction 3...

Vue realizes dynamic progress bar effect

This article example shares the specific code of ...