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 query duplicate data in mysql table

INSERT INTO hk_test(username, passwd) VALUES (...

A brief explanation of the reasonable application of table and div in page design

At the beginning of this article, I would like to ...

How to implement a password strength detector in react

Table of contents Preface use Component Writing D...

How to modify the initial password of a user in mysql5.7

When users install MySQL database for the first t...

Solution for front-end browser font size less than 12px

Preface When I was working on a project recently,...

SQL query for users who have placed orders for at least seven consecutive days

Create a table create table order(id varchar(10),...

Achieve 3D flip effect with pure CSS3 in a few simple steps

As a required course for front-end developers, CS...

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

JavaScript to implement mobile signature function

This article shares the specific code of JavaScri...

How to make a website look taller and more designed

“How to make a website look high-end? Or more des...

Django+vue registration and login sample code

register The front-end uses axios in vue to pass ...

Install Windows Server 2019 on VMware Workstation (Graphic Tutorial)

If prompted to enter a key, select [I don’t have ...