Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Saturday, December 12, 2020

How2 change Datadir path under MariaDB 10.3 running on CentOS 8 server

This tutorial will guide with the steps to change datadir in MariaDB and also provide with rollback steps in case it does not work as expected.

Configuration steps are as follows


    a) Plan for the server downtime and shutdown MariaDB.

            # systemctl stop mariadb

        Reconfirm the status of MariaDB is properly shutdown.

            # systemctl status mariadb


    b) Copy existing data to new datadir (in our case we will use /mnt/data), but replace this path as per your new datadir path.

            # rsync -av /var/lib/mysql /mnt/data

        Optional step : Above rsync command will copy all data files keeping ownership intact, but to ensure all directories and datafiles have correct ownership execute following command

           
# chown -R mysql:mysql /mnt/data/


    c) Rename original datadir so as to have a rollback plan in place and also to avoid confusion.

            # mv /var/lib/mysql /var/lib/mysql.old


    d) Update config files with new datadir path

        Update server config file

            
# vi /etc/my.cnf.d/mariadb-server.cnf

        in [mysqld] section, comment out original datadir and socket lines as it can be used to roll back changes

            
#datadir=/var/lib/mysql
            #socket=/var/lib/mysql/mysql.sock

        and add new values

            datadir=/mnt/data/mysql
            socket=/mnt/data/mysql/mysql.sock
 
        and save the file and proceed to updated client config file

            # vi /etc/my.cnf.d/client.cnf

        under client-mariadb section add this line

            [client-mariadb]
            
socket=/mnt/data/mysql/mysql.sock

        and save the file


    e) Start MariDB server

           
# systemctl start mariadb

        and check if mariadb is working fine

            # systemctl status mariadb

        Incase there is any error then you can try to debug the same or roll back steps as mentioned in section c & d and restart MariaDB and you will be back to original state


    f) To check the status, login into MariaDB console

            # mysql -uroot -p

        check if datadir is set correctly
        
           
> select @@datadir;

        and response should be as follows

            +-------------------+
            | @@datadir         |
            
+-------------------+
            | /mnt/data/mysql/  |
           
+-------------------+


    g) To check everything is working fine, create a database

            
> create database test;

        and if created successfully then proceed to clean up the test database. 

            > drop database test;

        and exit out of mariadb.


    h) After ensuring all the data is successfully copied and new Datadir path is working fine, delete the /var/lib/mysql.old folder to save on hdd space.

            # rm -rf /var/lib/mysql.old

With this we are done with moving Datadir path under MariaDB 10.3 and I hope this post help you with the required steps.

Tuesday, February 17, 2015

Howto disable / enable autostart of MariaDB 5.x & 10.x at system startup on Ubuntu 14.04.1 64bit

To disable autostart of MariaDB during system boot / startup do as follows

$ sudo update-rc.d -f mysql disable


and to enable it again do

$ sudo update-rc.d mysql enable

or

$ sudo update-rc.d mysql default

Monday, August 23, 2010

MyTop for MySql - Installation guide on CentOS

MyTop is the console-based tool for monitoring the overall performance of a MySQL server. The installation steps are as follows

# yum install perl-TermReadKey
# wget http://www.mysqlfanboy.com/mytop/mytop-1.9.tar.gz
# tar -zxvf mytop-1.9.tar.gz
# cd mytop-1.9
# perl Makefile.PL
# make
# make test
# make install


Now we need a config file as follows

# vi ~/.mytop

user=root
pass=YOURPASSWORD
host=localhost
db=YOURDBNAME
delay=5
port=3306
socket=/tmp/mysql.sock
batchmode=0
header=1
color=1
idle=1