Steps to modify the MySQL database data file path under Linux

Steps to modify the MySQL database data file path under Linux

After installing the MySQL database using the rpm installation method, the default path for the data files is /var/lib/mysql. However, the root directory is not suitable for storing data files.

Original path: /var/lib/mysql

Target path: /home/mysql_data/mysql

Linux system version: centos7.6

MySQL database version: 5.7.25

step:

1. Create a target path

mkdir -p /home/mysql_data

2. Shut down MySQL

systemctl stop mysqld

3. Copy data files

cp -arp /var/lib/mysql /home/mysql_data

4. Modify the configuration file /etc/my.cnf

Change the original paths in datadir and socket to the target paths

datadir=/home/mysql_data/mysql
socket=/home/mysql_data/mysql/mysql.sock

5. Start MySQL service

systemctl start mysqld

NOTE:

1. The error is as follows:

2019-12-22T08:32:42.430564Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:42.430599Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:42.430616Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-12-22T08:32:42.430898Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430923Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430936Z 0 [ERROR] InnoDB: Could not create the shared innodb_temporary.
2019-12-22T08:32:42.430952Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-12-22T08:32:43.038973Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:43.039021Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:43.039037Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-12-22T08:32:43.039046Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-12-22T08:32:43.039056Z 0 [ERROR] Failed to initialize builtin plugins.
2019-12-22T08:32:43.039063Z 0 [ERROR] Aborting

solve:

Execute the command:

setenforce 1

Restart again

2. The error is as follows:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

solve:

Modify the configuration file my.cnf and add or modify the following configuration:

[client]
socket = /home/mysql_data/mysql/mysql.sock

Summarize

The above is what I introduced to you about modifying the MySQL database data file path under Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • There is no problem with the Linux file path when deploying the window and Linux projects
  • Detailed explanation of common files and command paths in Kali Linux
  • How to query the full path of the running file in Linux
  • How to implement tar packing of specified path files in Linux
  • How to get the absolute path of a file through a file descriptor in Linux
  • How to view the path of the MySQL configuration file on the Linux server
  • Linux changes the path of mysql database files
  • Extract specific file paths in folders based on Linux commands

<<:  Vue Basics Introduction: Vuex Installation and Use

>>:  Methods and steps for deploying go projects based on Docker images

Recommend

Docker starts in Exited state

After docker run, the status is always Exited Sol...

How to set the border of a web page table

<br />Previously, we learned how to set cell...

The actual process of implementing the guessing number game in WeChat applet

Table of contents Function Introduction Rendering...

Detailed introduction of Chrome developer tools-timeline

1. Overview Users expect the web applications the...

JavaScript canvas to load pictures

This article shares the specific code of JavaScri...

How to start multiple MySQL databases on a Linux host

Today, let’s talk about how to start four MySQL d...

Docker starts MySQL configuration implementation process

Table of contents Actual combat process Let's...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

What is the use of the enctype field when uploading files?

The enctype attribute of the FORM element specifie...

Data URI and MHTML complete solution for all browsers

Data URI Data URI is a scheme defined by RFC 2397...

MySQL Innodb key features insert buffer

Table of contents What is insert buffer? What are...

A brief analysis of the best way to deal with forgotten MySQL 8 passwords

Preface Readers who are familiar with MySQL may f...

Nginx learning how to build a file hotlink protection service example

Preface Everyone knows that many sites now charge...

Implementing a simple web clock with JavaScript

Use JavaScript to implement a web page clock. The...