Friday 7 December 2012

Mysql database permissions


Grant all permissions to user "test_user" on the new database "foss"

         mysql >  grant  all  on  foss.*  to  'test_user'@'localhost'   identified  by   'test_user_password';

                   foss  ---> database name   
                   foss.*  ----> [database name] . [table name]                  

Grant all permissions to user "test_user" on all databases
                   
         mysql >  grant  all  on  *.*  to  'test_user'@'localhost'   identified  by   'test_user_password';                       

                      all   ----> all permission
                      *.*  ----> [database name] . [table name]

How To Grant Different User Permissions
            Here is a short list of other common possible permissions that users can enjoy.

ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)

CREATE- allows them to create new tables or databases
DROP- allows them to them to delete tables or databases
DELETE- allows them to delete rows from tables
INSERT- allows them to insert rows into tables
SELECT- allows them to use the Select command to read through databases
UPDATE- allow them to update table rows
GRANT OPTION- allows them to grant or remove other users' privileges


Sunday 2 December 2012

Backup and Restore MySQL Database Using mysqldump


How to backup mysql database using "mysqldump"

         mysqldump is an effective tool to backup MySQL database

Backup a single database

     [root@sysadmin ~]#  mysqldump   -u   root   -p   test   >   test.sql

         test --> database name
 test.sql --> dumpfile name

Backup multiple databases

              [root@sysadmin ~]#  mysqldump  -u  root  -p   --databases  test1  test2  >  test1_test2.sql

test1 and test2 --> database name

Backup all the databases

              [root@sysadmin ~]#  mysqldump  -u   root   -p   --all-databases  >  all-database.sql


How to Restore MySQL Database:

      [root@sysadmin ~]#  mysql  -u  root  -p  test  <  test.sql

test --> database name
  test.sql --> dumpfile name


Wednesday 21 November 2012

Create database and Drop database


How to create database :

 Mysql login with root user



Create a database "foss" and Verify that it’s there



How to remove database:

                   mysql>  drop  database  foss;




                     mysql>  exit

     

Saturday 10 November 2012

How to reset Mysql root password on linux

First stop the mysql daemon service

   # /etc/init.d/mysqld   stop

Then, run following command in terminal

   # mysqld_safe    --skip-grant-tables   & 

Now login mysql

   # mysql   -u   root   mysql

Change root  password

   mysql >  UPDATE  mysql.user  SET  Password=PASSWORD('MyNewPass') WHERE User='root';

   mysql> FLUSH PRIVILEGES;

   mysql> exit

Now start the mysql daemon service

   # /etc/init.d/mysqld   start

   #  mysql   -u   root   -p

I hope , Now you can able to login with root user.


Monday 5 November 2012

How to create user and set password in mysql


First login root user in mysql

        [root@sysadmin ~] # mysql -u root -p
 

Create the user

               mysql > create user test_user@localhost;

Set password for 'test_user'

          mysql > SET PASSWORD FOR 'test_user'@'localhost'  =  PASSWORD('test@1234');


Check test_user can able to login or not

      [root@sysadmin ~]# mysql  -u  test_user  -p
      Enter password:
 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.67-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit


 Successfully created user and set password. 


Check user list on mysql

                mysql> SELECT User FROM mysql.user; 


How to remove user in mysql

           mysql>  drop   user   'test_user'@'localhost';


Thursday 1 November 2012

Skype Installation and Configuration on Proxy Network in Ubuntu

Skype allows people to communicate with each other by Messaging, Voice calling and Video calling over internet.Now we are going to install Skype.

Installation of Skype


                  manivel@manivel-admin:~$ sudo apt-get install skype

To check whether skype installed or not.Once skype installed you will get below output

                  manivel@manivel-admin:~$ sudo dpkg --list | grep skype


sudo: unable to resolve host manivel-admin
 

ii  pidgin-skype    20110407+svn612+dfsg-1.1  Skype plugin for libpurple messengers
 

ii  pidgin-skype-dbg 20110407+svn612+dfsg-1.1 Skype plugin for libpurple messengers (debug symbols)
 

ii  skype   4.1.0.20.0-0ubuntu0.12.04.2     client for Skype VOIP and instant messaging service
 

ii  skype-bin    4.1.0.20.0-0ubuntu0.12.04.2     client for Skype VOIP and instant messaging service - binary files


If you want open skype via terminal then open the terminal and type "skype"

              manivel@manivel-admin:~$  skype





How to Configure Proxy on Skype 


        Go to desktop top panel there is Skype symbol then Right click ---> options and set your proxy details.


I hope this helps.....,

Sunday 21 October 2012

How to configure wget on a proxy network in Centos

When your Linux Centos system using Proxy server or your network environment require you to use proxy server to go to internet, you may need to configure wget to enable wget to download through that proxy server.  To enable wget download through proxy server for all user on your Centos system, you need to edit the "/etc/wgetrc" configuration file.

 Backup "wgetrc" configuration file before we start edit the "wgetrc" file.

             [root@sysadmin ~]#   cp   -p   /etc/wgetrc   /etc/wgetrc.bkp

Open the /etc/wgetrc configuration file and Remove the comment tag (#) https_proxy,http_proxy,ftp_proxy and use_proxy then put the proxy server address and proxy server port number.

             [root@sysadmin ~]#   vim   /etc/wgetrc



Test using "wget" to download something from internet..



Now you can able to download from Internet using wget command.

Friday 12 October 2012

How to configure yum on a proxy network in Centos

Now we are going to enable yum update through proxy server on Linux Centos system. So Backup "yum.conf" configuration file before we start edit the yum.conf file.

          [root@sysadmin ~]#   cp  -p   /etc/yum.conf   /etc/yum.conf.bkp


Open the yum.conf configuration file and put the http proxy server address and proxy port number

          [root@sysadmin ~]#   vim   /etc/yum.conf




If the proxy server require a user name and password... edit the /etc/yum.conf and add proxy user username and add proxy user password




 Then execute "yum clean all" command to clean/clear yum cache file




Then execute "yum update" command



I hope, it should work.

Wednesday 10 October 2012

Install EPEL and RPMFORGE Repository on CentOS 6.3 x86_64

Download and import GPG key for EPEL:

[root@manivel ~]# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6

Import GPG Key

    [root@manivel ~]# rpm –import RPM-GPG-KEY-EPEL-6

    [root@manivel ~]# rm -f RPM-GPG-KEY-EPEL-6

Download and Install EPEL software :

    [root@manivel ~]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

    [root@manivel ~]# rpm -ivh epel-release-6-8.noarch.rpm



Download and Install RPMFORGE software :


    [root@manivel ~]#  wget   http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

    [root@manivel ~]#  rpm   -ivh   rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

It should resolve your issue.



Saturday 30 June 2012

Installing Mysql on Centos


First we need to check mysql installed or not

          [root@sysadmin ~]#  rpm   -qa   mysql

Then not installed run this command

         [root@sysadmin ~]#  yum   install   mysql   mysql-server  -y

After installing the mysql and start the mysql daemon service

          [root@sysadmin ~]#   /etc/init.d/mysqld   restart

Output could like this

           Stopping mysqld: [ OK ]
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h linux password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[ OK ]
Starting mysqld: [ OK ]  

Set a password for root user at first time

           [root@sysadmin ~]#  mysqladmin   -u   root   password   'new-password'

Now installed the mysql.

Mysql starts automatically whenever the system boot so we will run this command

          [root@sysadmin ~]#   chkconfig   mysqld   on

Tuesday 12 June 2012

How to configure Apache Server on CentOS

Edit configuration file :

Open the Apache configuration file following location and modify

        [root@sysadmin]#  vim   /etc/httpd/conf/httpd.conf

                            Listen       10.102.152.198:80
                     ServerName     www.manivel.com
                    DocumentRoot  "/var/www/html/manivel/"

             save and close.


Now Restart the service

            [root@sysadmin]#  /etc/init.d/httpd  restart

Disable Security Enhanced Linux (SElinux) :

             [root@sysadmin]#  vim /etc/selinux/config



Check Security Enhanced Linux status using following command

            [root@sysadmin]#  getenforce

Disable Firewall setting :

           [root@sysadmin ~]#   system-config-firewall-tui



You want with Firewall setting follow 

Start the iptables service

       [root@sysadmin ~]#   /etc/init.d/iptables  start

Write iptables rule to allow HTTP (or) port 80

       [root@sysadmin ~]#   iptables   -t   filter  -A   INPUT   -i   eth0  -p   tcp   --dport  80   -j   ACCEPT

Save the above rule using below command

        [root@sysadmin ~]#   /etc/init.d/iptables  save

Now Restart the iptables service

        [root@sysadmin ~]#   /etc/init.d/iptables  restart

Testing HTTP working or not



Yes, HTTP is working.


Thursday 7 June 2012

How to install Apache server in Linux

Apache is one of the most popular web servers in Linux.

Install Apache HTTP Server on Centos 

          [root@sysadmin ~]#  yum   install   httpd   httpd-devel

 Now start the service

         [root@sysadmin ~]#  /etc/init.d/httpd  start

Set the apache service to start on boot

         [root@sysadmin ~]#  chkconfig  httpd  on

How to upgrade Apache HTTP server on Centos

First stop the apache service

         [root@sysadmin ~]#  /etc/init.d/httpd  stop

Then take backup the Apache configuration file

         [root@sysadmin ~]#  cp   -p   /etc/httpd/conf/httpd.conf   /httpd.conf-bkp

Upgrade the Apache HTTP server

         [root@sysadmin ~]#  yum   upgrade   httpd

Now Restart the service

          [root@sysadmin ~]#  /etc/init.d/httpd  restart

Sunday 20 May 2012

Extenal HDD mounting error on centos

I am trying to mount an external hard disk

[root@sysadmin ~]# mount   /dev/sdb1 /mnt/HDD/

mount: you must specify the file system type

but i am getting error. So i specified the file system type

[root@sysadmin ~]# mount -t ext4 /dev/sdb1 /mnt/HDD/

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
      missing codepage or helper program, or other error
      In some cases useful info is found in syslog - try
      dmesg | tail  or so




Solution:



Step: 1

I checked HDD detected or not, using following command

[root@sysadmin ~]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd967d967

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       31871   256000000   83  Linux
/dev/sda2   *       31871       60419   229313536   83  Linux
/dev/sda3           60419       60802     3072000   82  Linux swap / Solaris

Disk /dev/sdb: 2000.4 GB, 2000398933504 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x584d2cea

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      243201  1953512001    7  HPFS/NTFS


HDD detected. Hard disk name /dev/sdb1



Step:2

I installed the fuse-ntfs-3g-2010.10.2-1.el5.rf.x86_64 rpm package.

  #  yum   install  fuse-ntfs
                or
  #  wget http://marush.com/wp-content/uploads/2009/03/ntfs-3g-200921-el5i686.rpm

# rpm -ivh ntfs-3g-200921-el5i686.rpm

After installed that package again i tried

[root@sysadmin ~]# mount   /dev/sdb1 /mnt/HDD/

I mounted the External HDD.


Saturday 5 May 2012

How to Disable SELinux and Firewall on Centos


Disable Security Enhanced Linux (SElinux) 


If you want to stop temporarily SELinux using below steps

  [root@localhost ~]# setenforce 0

Check Security Enhanced Linux status using following command

            [root@sysadmin]#  getenforce

            Disabled

If you want to stop permanently  SELinux using below steps

 [root@sysadmin]#  vim /etc/selinux/config





Disable Firewall setting


           [root@sysadmin ~]#   system-config-firewall-tui



Remove  "* " symbol then click OK. Now firewall was disabled.


Friday 6 April 2012

Kill idle SSH sessions on linux


First check how many user current logged in server using "w" command




View all SSH sessions processes id using "pstree  -p" command





kill idle ssh session using "kill  PID" command



I hope, this would resolve your issue.

Friday 23 March 2012

SSH login without password in linux

You can login to a remote Linux server without entering password using ssh-keygen.

Create public and private keys using "ssh-keygen" on local-host. ssh-keygen have two algorithm  tsa and rsa.


 root@manivel-admin:~#   ssh-keygen   -t  rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): -->Press Enter
Enter passphrase (empty for no passphrase):  --------->    Press Enter
Enter same passphrase again:                     ------------->   Press Enter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
94:94:60:5a:5f:e8:ef:7f:6d:02:3b:f9:88:39:d2:6f root@manivel-admin
The key's randomart image is:
+--[ RSA 2048]----+
|      +..o.      |
|     + ooo       |
|    .  .+        |
|       ..        |
|        S.       |
|          . .    |
|         o   + . |
|        . +oE.o o|
|         .o=++.o |
+-----------------+
root@manivel-admin:~# 

Copy the public key localhost to remote-host using "scp" command.

  root@manivel-admin:~# scp  -r  .ssh/id_rsa.pub  test@10.2.12.1:/home/test/.ssh/authorized_keys

Notes: If  .ssh directory is not there in /home/test/ .You will create .ssh


We need to set permission for .ssh directory and authorized_keys file in "Remote host".

  test@manivel:~$  chmod  755  .ssh/

  test@manivel:~$  chmod  644  .ssh/authorized_keys

Login to remote-host without entering the password

  root@manivel-admin:~#   ssh   test@10.2.12.1
                    [Note: SSH did not ask for password.]

  test@manivel:~$  [Note: You are on remote-host here]

Saturday 10 March 2012

500 OOPS: cannot change directory:/home/user, Login failed on Vsftpd

You want to login ftp server using system user(local or remote) and want to get into home directory of that user.You are trying to connect ftp server but getting below error



Above error occurs when SELinux is Enforcing mode.First you need to check SELinux status using below command.

[root@localhost ~]# getenforce
Enforcing

You need to change SELinux mode Enforcing to Permissive mode

 [root@localhost ~]# setenforce  0

Now check again SELinux status

  [root@localhost ~]# getenforce 
  Permissive

Now you can able to login ftp server using user (ftp-user) and check user home directory using "pwd" command


If you want to access remote machine via ftp then Disable Firewall and SELinux. 

Friday 2 March 2012

Making ISO file on command line using "mkisofs"


Single directory to iso file
 # mkisofs -o   test.iso   test/
output would like this
I: -input-charset not specified, using utf-8 (detected in locale settings)
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
5765 extents written (11 MB)
Multiple directory to iso file
# mkisofs -o   test.iso   test/  test1/  test2/

Monday 20 February 2012

FTP ( VSFTPD ) Server Installation on Linux

Vsftpd ( Very Secure FTP Daemon ) is an FTP server for Unix like Operating systems.

Install Vsftpd

                  [root@sysadmin sysadmin]#  yum   install   vsftpd  ftp

     Now restart the service

                  [root@sysadmin sysadmin]#  /etc/init.d/vsftpd  restart

     Check vsftpd process status

                  [root@sysadmin sysadmin]#  ps  -ef  |  grep   vsftpd


                  root     24457     1  0 22:07 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
                  root     24779 21553  0 23:00 pts/0    00:00:00 grep vsftpd

     Check ftp server port status

                 [root@sysadmin ~]#  netstat   -nat  |   grep  21

                 tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      

    Set the vsftpd service to start on boot


                [root@sysadmin ~]#  chkconfig  vsftpd  on

Friday 10 February 2012

How to backup file and directory using "Rsync"


Backup Local host to Remote host 

First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location

   [root@server ~]#   rsync   -avzr   /Datas   manivel@192.168.0.123:/home/manivel/

-z --> to enable compression
-r --> recursive
-v --> verbose
-a --> Preserves permissions, timestamp and symbolic links.

Backup Remote host to Local host

     [root@server ~]#   rsync   -avzr    manivel@192.168.0.123:/home/manivel/Datas  /test/


You want to view the rsync Progress during Transfer the files use option "-P"

     [root@server ~]#   rsync   -avzP    manivel@192.168.0.123:/home/manivel/Datas  /test/

Wednesday 25 January 2012

Introduction of "Rsync"


"Rsync" utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server.

Important features of rsync

  • Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
  • Security: rsync allows encryption of data using ssh protocol during transfer
  • Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
  • Privileges: No special privileges are required to install and execute rsync

Syntax

            [root@server ~]#   rsync   options   source   destination

Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.


If you want Rsync man page Click here

Sunday 15 January 2012

SSH installation on Centos

We need to install two package
                 1. Openssh-server
                 2. Openssh-clients

First check Openssh-server and Openssh-clients packages installed or not

  [root@sysadmin sysadmin]#  rpm  -qa   openssh*
output would like this

openssh-clients-5.3p1-70.el6_2.2.x86_64
openssh-askpass-5.3p1-70.el6_2.2.x86_64
openssh-server-5.3p1-70.el6_2.2.x86_64
openssh-5.3p1-70.el6_2.2.x86_64

You did not get above output .You need to install the Openssh packages ( which are installed by default untill and unless you removed it or skipped it while installing Centos)


           [root@sysadmin sysadmin]#  yum   install  openssh-server   openssh-clients

Then start the SSH service

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   start

After that check SSH service running or not

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   status

If you want to restart the service , using restart command

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   restart

SSH starts automatically whenever the system boot so we will run this command

           [root@sysadmin sysadmin]#   chkconfig   sshd   on

Friday 6 January 2012

How to Setup Static or Dynamic IP Address in Centos

After centos operting system installation, i can't able to communicate another machine. At that time i checked and found my machine network interface (eth0) down. I got my network interface information using "ifconfig" command

            [root@localhost ~]# ifconfig

                   lo          Link encap:Local Loopback  
                                inet addr:127.0.0.1  Mask:255.0.0.0
                                inet6 addr: ::1/128 Scope:Host
                                UP LOOPBACK RUNNING  MTU:16436  Metric:1
                                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                                collisions:0 txqueuelen:0 
                                RX bytes:0 (0.0 MiB)  TX bytes:0 (0.0 MiB)

Above result is showing network interface down. So i used below command to up the interface.

             [root@localhost ~]#  ifup  eth0

After that again i checked. It was up

              [root@localhost ~]# ifconfig

                    eth0      Link encap:Ethernet  HWaddr 10:78:D2:54:19:BD  
                                 inet6 addr: fe80::1278:d2ff:fe54:19bd/64 Scope:Link
                                 UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
                                RX packets:1055 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:4 errors:0 dropped:0 overruns:0 carrier:5
                                collisions:0 txqueuelen:1000 
                                RX bytes:88232 (86.1KiB)  TX bytes:328 (328.0 b)

                    lo          Link encap:Local Loopback  
                                inet addr:127.0.0.1  Mask:255.0.0.0
                                inet6 addr: ::1/128 Scope:Host
                                UP LOOPBACK RUNNING  MTU:16436  Metric:1
                                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                                collisions:0 txqueuelen:0 
                                RX bytes:0 (0.0 MiB)  TX bytes:0 (0.0 MiB)

I had tried two methods for setting up ip address,

    1. DHCP IP Address
    2. Static IP Address

Network interface configuration file location "/etc/sysconfig/network-scripts/ifcfg-eth0 "

Configure Dynamic IP Address :


 First i configured dynamic ip address for my machine. This steps i used for that.
        

         [root@localhost ~]# vim  /etc/sysconfig/network-scripts/ifcfg-eth0

                                  DEVICE="eth0"
                                  BOOTPROTO="dhcp"
                                  HWADDR=10:78:D2:54:19:BD
                                  NM_CONTROLLED="yes"
                                  ONBOOT="yes"
                                  TYPE="Ethernet"
                                  UUID="6b03d1a2-8bb1-4d7b-bd03-8a2e2b4acccf"

                      : wq

After that i restarted the network service

         [root@localhost ~]#  /etc/init.d/network  restart

Configure Static IP Address :


Second i tried static ip address for my machine. This steps i used for that

        [root@localhost ~]# vim  /etc/sysconfig/network-scripts/ifcfg-eth0

                                  DEVICE="eth0"
                                  BOOTPROTO="static"
                                  HWADDR=10:78:D2:54:19:BD
                                  NM_CONTROLLED="yes"
                                  ONBOOT="yes"
                                  TYPE="Ethernet"
                                  UUID="6b03d1a2-8bb1-4d7b-bd03-8a2e2b4acccf"
                                  IPADDR=192.168.0.100
                                  NETMASK=255.255.255.0
                                
                              :wq  


After that i restarted the network service

             [root@localhost ~]#  /etc/init.d/network  restart


Wednesday 4 January 2012

Linux Set Date and Time From a Command Prompt:

Here i am going to show how to check date and time using "date" command

  root@manivel-admin:~#  date
  Thu Mar 14 23:51:04 IST 2010

If it is showing wrong data and time, you can set date and time using following command

How to set date :

root@manivel-admin:~#  date   +%Y%m%d  -s   "20120104"

     -s   ----> set
    %Y ---> year
    %m  ----> month
    %d  ----> date

How to set time :

root@manivel-admin:~#   date   +%T%p  -s   "10:10:30AM"

     %T  ---> time
     %p  ---->either AM or PM