MySql - Change data folder


I just installed Percona Server 5.7 and want to change the data folder.

I proceeded as follows:

  1. I stopped the service - service mysqld stop
  2. I edited the /etc/percon-server.conf.d/mysqld.cnf file and changed the new path (datadir = /opt1/mysql-data/mysql)
  3. I copied the entire contents of /var/lib/mysql to /opt1/mysql-data/mysql preserving the attributes
  4. I tried to restart the database and received the following message:

“Job for mysqld.service failed because the control process exited with error code. See” systemctl status mysqld.service “and” journalctl -xe “for details.”

If I return to the original settings everything returns to normal.

Any suggestion?


short answer:

chcon -R -u system_u -r object_r -t mysqld_db_t

Long (and useful) answer can be found in this blog link