MySQL database under Linux modify the data file path

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

The original path: / var / lib / mysql
destination path: / Home / mysql_data / MySQL
Linux System Version: centos7.6
MySQL database version: 5.7.25

Steps:
1. Create the destination path
mkdir -p /home/mysql_data
2, shut down MySQL
systemctl stop mysqld
3, copy the data files
cp -arp /var/lib/mysql /home/mysql_data
4, modify the configuration file /etc/my.cnf
the original path datadir and socket may be modified to target path
datadir=/home/mysql_data/mysql
socket=/home/mysql_data/mysql/mysql.sock
5, start the MySQL service
systemctl start mysqld

NOTE:
. 1, given 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

Solution:
Execute the command:
setenforce 1
restart

2, being given as follows:
of Can not Connect to local MySQL Server through socket '/var/lib/mysql/mysql.sock'
resolve:
to modify the configuration file my.cnf, add or modify the following configuration:

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

Guess you like

Origin www.cnblogs.com/Lans-word/p/12080177.html