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

VMware virtual machine installation Apple Mac OS super detailed tutorial

Table of contents Summarize Sometimes we need to ...

MySQL users and permissions and examples of how to crack the root password

MySQL Users and Privileges In MySQL, there is a d...

Nginx solves cross-domain issues and embeds third-party pages

Table of contents Preface difficulty Cross-domain...

How to underline the a tag and change the color before and after clicking

Copy code The code is as follows: a:link { font-s...

Basic learning and experience sharing of MySQL transactions

A transaction is a logical group of operations. E...

Vue component library ElementUI implements table loading tree data tutorial

ElementUI implements a table tree list loading tu...

Summary of using MySQL isolation columns and prefix indexes

Table of contents Isolate Data Columns Prefix Ind...

How to cancel the background color of the a tag when it is clicked in H5

1. Cancel the blue color of the a tag when it is ...

Detailed explanation of CSS3+JS perfect implementation of magnifying glass mode

About a year ago, I wrote an article: Analysis of...

Installation and configuration of MySQL 5.7.17 free installation version

MYSQL version: MySQL Community Server 5.7.17, ins...

How to create a view in MySQL

Basic syntax You can create a view using the CREA...

How to implement image mapping with CSS

1. Introduction Image maps allow you to designate...