Home > Database > Mysql Tutorial > Change the default path of mysql data file under linux

Change the default path of mysql data file under linux

王林
Release: 2020-01-22 20:33:25
forward
2180 people have browsed it

Change the default path of mysql data file under linux

After installing the MySQL database using the rpm installation method, the default path of the data file is /var/lib/mysql, but the root directory is not suitable for storing data files, so we need Change the default path of the database file.

The change method is as follows:

Environment introduction:

Original path:/var/lib/mysql

Target path:/home/mysql_data/mysql

Linux system version: centos7.6

MySQL database version: 5.7.25

Free learning video tutorial: mysql video tutorial

Specific steps:

1. Create the target path

mkdir -p /home/mysql_data
Copy after login

2. Close MySQL

systemctl stop mysqld
Copy after login

3. Copy the data file

cp -arp /var/lib/mysql /home/mysql_data
Copy after login

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

Modify the original path in datadir and socket to the target path

datadir=/home/mysql_data/mysql
socket=/home/mysql_data/mysql/mysql.sock
Copy after login

5. Start the MySQL service

systemctl start mysqld
Copy after login

NOTE:

1. The error is reported as follows:

Change the default path of mysql data file under linux

Solution:

Execute command:

setenforce 1
Copy after login

Restart.

2. The error is reported as follows:

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

Solution:

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

[client]socket = /home/mysql_data/mysql/mysql.sock
Copy after login

Recommended related articles and tutorials: mysql tutorial

The above is the detailed content of Change the default path of mysql data file under linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template