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

When you enter a URL, what exactly happens in the background?

As a software developer, you must have a complete...

Example of using UserMap in IMG

usemap is an attribute of the <img> tag, use...

Implementation script for scheduled database backup in Linux

Table of contents Scenario: The server database n...

XHTML Basic 1.1, a mobile web markup language recommended by W3C

W3C recently released two standards, namely "...

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

Solution to multiple 302 responses in nginx proxy (nginx Follow 302)

Proxying multiple 302s with proxy_intercept_error...

How to quickly use mysqlreplicate to build MySQL master-slave

Introduction The mysql-utilities toolset is a col...

Nginx reverse proxy learning example tutorial

Table of contents 1. Reverse proxy preparation 1....

Mysql experiment: using explain to analyze the trend of indexes

Overview Indexing is a skill that must be mastere...

Docker container operation instructions summary and detailed explanation

1. Create and run a container docker run -it --rm...

Detailed explanation of the concept, principle and usage of MySQL triggers

This article uses examples to explain the concept...

A brief understanding of the differences between MySQL InnoDB and MyISAM

Preface MySQL supports many types of tables (i.e....

HTML+CSS merge table border sample code

When we add borders to table and td tags, double ...

Detailed explanation of how to detect and prevent JavaScript infinite loops

Table of contents Preface Fix infinite loop in fo...