Friday, March 18, 2011

Listing the category and subcategory from single table

You table structure

create table categories
( id       integer     not null  primary key
, name     varchar(37) not null
, parentid integer     null
, foreign key parentid_fk (parentid)
      references categories (id)
);

Your Sql

select root.name  as root_name
     , down1.name as down1_name
     , down2.name as down2_name
     , down3.name as down3_name
  from categories as root
left outer
  join categories as down1
    on down1.parentid = root.id
left outer
  join categories as down2
    on down2.parentid = down1.id
left outer
  join categories as down3
    on down3.parentid = down2.id
 where root.parentid is null
order
    by root_name
     , down1_name
     , down2_name
     , down3_name

Monday, February 21, 2011

Archive and extract files using command line

To create the  archive files use following command

tar -czf test.tar.gz test/

To extract the files use following command

tar -xzf test.tar.gz 

 


Thursday, January 13, 2011

To repair Mysql Table

To repair Mysql Table use the following command.
 
$ myisamchk -r /usr/local/mysql/data/dbname/tablename.MYI

Thanks
Vishnu U

Friday, December 17, 2010

Mysql Dump and restore single database

Use the following command to dump and restore mysql database

mysqldump -u root -p dbName  > /var/www/dbBackup.sql
mysql -u root -p dbName < /var/www/dbBackup.sql

Monday, December 13, 2010

SCP command to transfer files using putty or shell

transfer the files from user localhost machine to remote server

$scp -r /home/myfolder/* root@remote server ip:/root/myfolder

if remote server running on different port

$scp -r -P remoteserverportnumer /home/myfolder/* root@remote server ip:/root/myfolder

Monday, November 29, 2010

install clamAV on httpd server

We need to check following
php-devel and clamav-devel.

To check for the software, use the commands below:

CODE
rpm -q php-devel


CODE
rpm -q clamav-devel


If nothing is returned from either rpm command, you will need to install the devel for the appropriate version.
If not installed the php-devel and clamav-devel install using yum
like

CODE
yum install php-devel

extract the library

CODE
tar xvzf php-clamavlib-0.12a.tar.gz

CODE
cd php-clamav-0.1

CODE
phpize

CODE
./configure --with-clamav

CODE
make

CODE
cp modules/clamav.so /usr/lib/php/modules

Note: /usr/lib/php/modules is my modules directory. Your module directory may be different. Search /etc/php.ini for extension_dir to get yours.

Edit /etc/php.ini (Make sure you make a backup!)
Add the following under the "Dynamic Extensions" section:

CODE
extension=clamav.so



[clamav]

clamav.dbpath="/var/clamav"

clamav.maxreclevel=0

clamav.maxfiles=0

clamav.archivememlim=0

clamav.maxfilesize=0

clamav.maxratio=0

Note: My clamav.dbpath may be different than yours. Do a simple locate main.cvd for the db directory.

Test to see if it works:
[PHP] echo cl_info() . "
";

$file = "/tmp/eicar.com";
cl_scanfile_ex($file, CL_SCAN_STDOPT, $virus, $retcode);
if ($retcode == CL_VIRUS)
echo $file . " returns: " . cl_pretcode($retcode) . " virus name: " . $virus . "
";
else
echo $file . " returns: " . cl_pretcode($retcode) . "
";
?>[/PHP]

Go to http://www.phpclamavlib.org/ for more information on the functions included with this module.

Good luck!

Mysql dump and restore database

To dump and restore all database of mysql server use following command

mysqldump -u root -psecret --all-databases > /var/www/backup.sql
mysql -u root -psecret < /var/www/backup.sql