MySQL installment into different partitions on server

  • by

If you have dedicated space assigned to your MySQL installation it isnt too obvious on how to install it there.

Benefit:
– System can keep running now matter how big the MySQL database becomes

Concept:
– Basic intall location is in root directory.
– We must move it to the new location.
– Ensure folder privileges are correct

Proceedure:

sudo service mysqld stop
macke a backup:
cp -r var/lib/mysql var/lib/mysql.backup

move to new location:
mv /var/lib/mysql /new/directory/

For Centos 8:
under /etc/my.cnf.d there are two files, one for client (connecting to server) and one for server setup. Both must be setup correctls.

client.cnf
[client]
socket=/new/location/mysql/mysql.sock
port=3306

server.cnf
[mysqld]
datadir=/new/directory/mysql
socket=/new/directory/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

change ownership of new location:
chown -R mysql:mysql /new/directory/

check SElinux context:
ls -Z

change context selinux
chcon -R -t mysqld_db_t /db

remove this file if the mysql cannot write to it which bocks startup
/db/mysql/mysql.sock

sudo service mysqld start
sudo service mysqld status

other commands
systemctl restart NetworkManager

refs:
https://www.mysqltutorial.org/mysql-administration/stop-mysql/
https://www.psce.com/en/blog/2012/04/12/how-to-install-and-configure-a-linux-server-for-mysql/
http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html
https://www.thegeekstuff.com/2016/05/move-mysql-directory/
https://www.digitalocean.com/community/tutorials/how-to-change-a-mariadb-data-directory-to-a-new-location-on-centos-7

Leave a Reply

Your email address will not be published. Required fields are marked *