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

Change the default path of mysql data file under linux

王林
王林forward
2020-01-22 20:33:252135browse

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

2. Close MySQL

systemctl stop mysqld

3. Copy the data file

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

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

5. Start the MySQL service

systemctl start mysqld

NOTE:

1. The error is reported as follows:

Change the default path of mysql data file under linux

Solution:

Execute command:

setenforce 1

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

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete