Sunday, February 14, 2010

Shell Scripting - referrence

-nt : Newer than
-ot : Older than
-gt : Greater than
-lt : Less than
-ge : Greater than or equal to
-le : less than or equal to
-eq : equal to
-ne : not equal to

check if the name "abc" is file or not
test -f abc; echo $? - if o/p is 0 then its a file else its a directory

also,
[-f abc]; echo $?

to check socket files eg mysql.sock
test -S /var/lib/mysql/mysql.sock; echo $? - if o/p is 0 then its socket file else not

To check null (zero size) files
test -s log1.log; echo $? - if o/p is 0 then its not a zero byte file.

man test - for all details

Thursday, January 14, 2010

MySQL - some basic command

Create new Database

create database DataBaseName;

Create User

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

Grant privileges on Datatabase

GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost'; - limited privileges
or
GRANT ALL ON *.* TO 'user1'@'localhost'; - All privileges
or
GRANT ALL PRIVILEGES ON * . * TO 'sunil'@'localhost' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; - root level privileges

Backup Database
mysqldump -u username -p -h hostname DatabaseName > exportedfilename.sql

Restore Database from dump
mysqldump -u username -p -h hostname DatabaseName < mysqldumpfilename.sql

Find version of mysql

select version();

Change Password for user
update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='user';
mysql> flush privileges;