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 expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

Axios project with 77.9K GitHub repository: What are the things worth learning?

Table of contents Preface 1. Introduction to Axio...

Analysis of the process of implementing Nginx+Tomcat cluster under Windwos

Introduction: Nginx (pronounced the same as engin...

Implementation of check constraints in MySQL 8.0

Hello everyone, I am Tony, a teacher who only tal...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

Gojs implements ant line animation effect

Table of contents 1. Gojs Implementation 1. Drawi...

WEB standard web page structure

Whether it is the background image or the text siz...

Design Reference Beautiful and Original Blog Design

All blogs listed below are original and uniquely ...

Several ways to encapsulate axios in Vue

Table of contents Basic Edition Step 1: Configure...

js realizes horizontal and vertical sliders

Recently, when I was doing a practice project, I ...

Introduction to scheduled tasks in Linux system

Table of contents 1. Customize plan tasks 2. Sync...

Detailed explanation of how to use Node.js to implement hot reload page

Preface Not long ago, I combined browser-sync+gul...

How to recover data after accidentally deleting ibdata files in mysql5.7.33

Table of contents 1. Scenario description: 2. Cas...