Sunday, April 16, 2017

Changing the default MySQL/MariaDB Data Directory

සුභ දවසක් , අද මම කියලා දෙන්න යන්නේ කොහොමද MySQL/MariaDB වල default data saving directory එක change කරගන්න විදිය.ගොඩක් වෙලාවට HDD එකේ space අඩුවුණාම අපිට මේ විදියට data saving location එක වෙනස් කරන්න වෙනවා

Steps


  • Data move කිරීමට අවශ්‍ය ස්ථානයේ folder එකක් සාදන්න එයට mysql user permission ලබා දෙන්න


  • දැනට භාවිතා කරන MySQL directory එක බලාගැනීමට පහත command එක enter කරන්න


  • ඉදිරි කටයුතු සදහා දැනට run වෙමින් පවතින MySQL/MariaDB instence එක stop කල යුතුය (Data loss වීම හා damage වීම වලක්වාලීම සදහා )


  • ඔබ භාවිතා කරනුයේ MySQL නම් හා OS එක CentOS/Fedora/Redhat නෙවෙයි නම් මෙම command use කරන්න
    • # service mysqld stop
    • # service mysqld status
    • OR
    • # service mysql stop
    • # service mysql status
  • ඊලග පියවරදී , දැනට ඇති data (Excisting data) අලුත් directory එකට මාරු කරන්න (2 වෙනි පියවරේ ඇති directory එකේ සිට අලුත් directory එකට)


  • අලුත් directory එක සදහා Database engine එකහි configuration වෙනස් කිරීම 
    • my.cnf modify කිරීම
[mysqld]
datadir=/mnt/mysql-data/mysql
socket=/mnt/mysql-data/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[client]:
port=3306
socket=/mnt/mysql-data/mysql.sock

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

  • SELinux Security Context අලුත්  Data Directory සදහා set කිරීම (CentOS/Redhat OS සදහා පමණි )
    • semanage fcontext -a -t mysqld_db_t "/mnt/mysql-data(/.*)?"
    • restorecon -R /mnt/mysql-data


  • අවසන් පියවර , MySQl/MariaDB engine එක නැවත ආරමිභ කරන්න
    • Redhat/CentOS
    • # systemctl start mariadb
    • # systemctl is-active mariadb
    • ------------- Ubuntu/MySQL------------- 
    • # service mysqld start
    • # service mysqld status
    • OR
    • # service mysql start
    • # service mysql status

  • Verify කිරීම





SITTHAMA

Sinhala Support


Followers

Designed By Seo Blogger Templates