Solve the error problem caused by modifying mysql data_dir

Solve the error problem caused by modifying mysql data_dir

Today, I set up a newly purchased Alibaba Cloud ECS environment (Ubuntu 16.04 LTS). I need to save the MySQL data on the newly mounted disk (mounted to /mnt). First, I stop the MySQL service, and then check the location where the MySQL data is saved:

vi /etc/mysql/mysql.conf.d/mysqld.cnf

I found datadir=/var/lib/mysql , which is the directory where the data is located, so I changed it to datadir=/mnt/mysql , then saved it, and finally copied the data saved in mysql to /mnt:

cp -r /var/lib/mysql /mnt
chown -R mysql:mysql /mnt/mysql

After the copy is complete, I thought everything was ready, so I started the mysql service:

systemctl start mysql

But I found that the startup failed, so I looked at the mysql error log:

tail -f -n100 /var/log/mysql/error.log

The error information is as follows:

[Warning] Can't create test file /mnt/mysql/iZwz9c03srb2lq9l374if5Z.lower-test

If you think about it carefully, there should be no problem with the mysql configuration. Check the apparmor configuration:

vi /etc/apparmor.d/usr.sbin.mysqld

The following configuration was found:

# Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

What a pitfall. I just changed datadir的/var/lib/mysql , but it is still restricted here, so I changed it to:

# Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/mnt/mysql/ r,
/mnt/mysql/** rwk,

save. Restart the apparmor service:

service apparmor restart

Then start the mysql service again:

systemctl start mysql

The service finally started successfully. . .

The above is the editor's introduction to solving the error problem caused by modifying mysql data_dir. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. Thank you very much for your support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Solution to the problem that Mysql cannot start due to modification of datadir

<<:  Detailed explanation of the pitfalls of nginx proxy socket.io service

>>:  The core process of nodejs processing tcp connection

Recommend

How to install MySQL 5.7.17 and set the encoding to utf8 in Windows

download MySQL official download, select Windows ...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

How to simulate network packet loss and delay in Linux

netem and tc: netem is a network simulation modul...

JavaScript programming through Matlab centroid algorithm positioning learning

Table of contents Matlab Centroid Algorithm As a ...

Learning about UDP in Linux

Table of contents 1. Introduction to UDP and Linu...

Talking about the practical application of html mailto (email)

As we all know, mailto is a very practical HTML ta...

Some tips on deep optimization to improve website access speed

<br />The website access speed can directly ...

Getting Started with MySQL - Concepts

1. What is it? MySQL is the most popular relation...

Detailed explanation of MySQL combined index method

For any DBMS, indexes are the most important fact...

MYSQL string forced conversion method example

Preface Since the types of the same fields in the...

Bootstrap 3.0 study notes grid system case

Preface In the previous article, we mainly learne...

In-depth understanding of asynchronous waiting in Javascript

In this article, we’ll explore how async/await is...

A Brief Discussion on the Navigation Window in Iframe Web Pages

A Brief Discussion on the Navigation Window in If...

Tutorial for installing MySQL 8.0.18 under Windows (Community Edition)

This article briefly introduces how to install My...