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

...

Detailed steps for installing and configuring MySQL 8.0 on CentOS 7.4 64-bit

Step 1: Get the MySQL YUM source Go to the MySQL ...

How to insert pictures into HTML pages and add map index examples

1. Image formats supported on the WEB: GIF: can s...

How to add custom system services to CentOS7 systemd

systemd: The service systemctl script of CentOS 7...

Overview of the Differences between Linux TTY/PTS

When we type a letter on the keyboard, how is it ...

TypeScript union types, intersection types and type guards

Table of contents 1. Union Type 2. Crossover Type...

jQuery implements form validation function

jQuery form validation example / including userna...

HTML basic summary recommendation (title)

HTML: Title Heading is defined by tags such as &l...

How to enable the slow query log function in MySQL

The MySQL slow query log is very useful for track...

CSS and JS to achieve romantic meteor shower animation

1. Rendering 2. Source code HTML < body > &...

Detailed description of common events and methods of html text

Event Description onactivate: Fired when the objec...

Develop a vue component that encapsulates iframe

Table of contents 1. Component Introduction 2. Co...

How to install and deploy zabbix 5.0 for nginx

Table of contents Experimental environment Instal...