How to move MySQL data directory

I have the default mysql configuration, thats why my data folder is over the /var/ partition,and since this partition is keeping without free space, I wanted to move my data folder.

I used the following steps to move MySQL default directory in cPanel.

First stop MySQL service on the server.

root@justgeek~]# /etc/init.d/mysql stop

Create New MYSQL directory where you want to move your data.

root@justgeek~]# mkdir /home/mysql

Now, move MySQL directory

root@justgeek~]# mv /var/lib/mysql /home/mysql

Edit the my.cnf file

root@justgeek~]# vi /etc/my.cnf

Now in the mysqld section add the following

datadir=/home/mysql

Now start MySQL service.

root@justgeek~]# /etc/init.d/mysqld start

Once this is done verify your websites and make sure that everything is working properly. Just in case if you face any issues you can contact us VIA contact page.

 

Read More

How do I Compress a Directory in Linux.

It is very easy to compress a Whole Linux/UNIX directory. It is useful to backup files, email all files. It is called as a compressed archive. GNU tar command is best for this work. It can be use on remote Linux or UNIX server. It creates archive and compress it.

You need to use tar command as follows (syntax of tar command):

tar -zcvf archive-name.tar.gz directory-name

Where,

-z: Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

For example, you have directory called /home/jerry/prog and you would like to compress this directory then you can type tar command as follows:

root@justgeek~]# tar -zcvf thisdirectory-11june2015.tar.gz /home/justgeek/thisdirectory

Above command will create an archive file called thisdirectory-11june2015.tar.gz in current directory. If you wish to restore your archive then you need to use following command (it will extract all files in current directory):

root@justgeek~]# tar -zxvf thisdirectory-11june2015.tar.gz

Where,

-x: Extract files

If you wish to extract files in particular directory, for example in /tmp then you need to use following command:

root@justgeek~]# tar -zxvf thisdirectory-11june2015.tar.gz -C /tmp
root@justgeek~]# cd /tmp
root@justgeek~]# ls -

Read More

How to remove files using find command

There are many situation when you will need to use find command to delete the files. First one is that when that when you want to remove some particular files, which are located in many subdirectories then you are use find command.

Second Situation is that when the simple rm command gives the error “Argument list too long”. Here it is the best to use find command to delete lakhs of files at once.

root@justgeek~]# rm -rf .careers.cur.1379*
-bash: /bin/rm: Argument list too long
root@justgeek~]#

Linux or UNIX – Find and remove file syntax

find dir-name criteria action

find . -name "FILE-TO-FIND" -exec rm -rf {} \;

OR

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

The only difference between above two syntax is that the first command remove directories as well where second command only removes files. Options:

Examples of find command

WARNING! These examples may crash your computer if executed. Before removing file makes sure, you have backup of all-important files. Do not use rm command as root user it can do critical damage to the system.

Find all files having .bak (*.bak) extension in the current directory and remove them:

root@justgeek~]# find . -type f -name "*.bak" -exec rm -f {} \;

Find all core files in the / (root) directory and remove them (be careful with this command):

root@justgeek~]# find / -name core -exec rm -f {} \;

Find all *.bak files in the current directory and removes them with confirmation from user:

root@justgeek~]# find . -type f -name "*.bak" -exec rm -i {} \;

Read More