Wednesday, June 15, 2011

Solaris and Linux Runlevel

Default Linux Run Level: Total 7 Run Level
RunLevel 0: Halt System – To shutdown the system
RunLevel 1: Single user mode
RunLevel 2: Basic multi user mode without NFS
RunLevel 3: Full multi user mode (text based)
RunLevel 4: unused
RunLevel 5: Multi user mode with Graphical User Interface
RunLevel 6: Reboot System
Default Solaris Run Level: Total 8 Run Level
RunLevel S: Single user state (useful for recovery)
RunLevel 0: Access Sun Firmware (ok> prompt)
RunLevel 1: System administrator mode
RunLevel 2: Multi-user w/o NFS
RunLevel 3: Multi-user with NFS
RunLevel 4: Unused
RunLevel 5: Completely shutdown the host (like performing a power-off)
RunLevel 6: Reboot but depend upon initdefault entry in /etc/inittab

Setup Subversion Server on Ubuntu

Step: 1 Installing the Subversion package
#apt-get install subversion
Step:2  Configure Subversion Directory
#mkdir –p  /home/svn/repository
Step 3 Configure Subversion group
#groupadd svn
#chgrp svn /home/svn/repository
#chmod g+rw /home/svn/repository
(you need to make sure that all new files and directories created in the repos directory (in other words, anything committed to the repositories) will also be owned by the group)
#chmod g+s /home/svn/repository
#usermod –a –G svn user1 (Assign users to svn group)
#usermod –a –G svn user2 (Assign users to svn group)
Step 4: Creating a New repository
#svnadmin create /home/svn/repository/test
Step 5: Checkout Repository
#svn checkout file:///home/svn/repository/test
Output: Checked out revision 0
Step 6: Add new files to Empty repository
#cd test
# echo ‘Hello, World!’ > hello.txt
#svn add hello.txt
Output : A         hello.txt
Step 7 : Commit files
#svn commit -m “Added a ‘hello world’ text file.”
Output :
Adding         hello.txt
Transmitting file data .
Committed revision 1.
Accessing SVN repository
Step 1:  Configure Users for Access SVN repository.
#vi /home/svn/repository/conf/authz
(Add below entry)
User1 = rw
User1 = rw
User2 = rw
(save file)
#vi /home/svn/repository/conf/passwd
(Add below entry)
(save file)
Step 2: Configure files for authentication
# rm –rf /home/svn/repository/test/conf/authz
# rm –rf /home/svn/repository/test/conf/passwd
#vi /home/svn/repository/conf/svnserve.conf
anon-access = none
password-db = /home/svn/repository/conf/passwd
realm = Team
Step 3: Start repository
#svnserve -d –foreground -r /home/svn/ repository
Step 4 : Test the Repository
#svn checkout svn://ipaddress/test –username user1
Step 5: Initialize the Script at Startup
#move svnserve /etc/init.d/
# chmod +x /etc/init.d/subserve
#update-rc.d svnserve defaults

Basic MySQL Commands

To login (from unix shell) use -h only if needed.
#mysql -h hostname -u root -p
Create a database on the sql server.
mysql> create database [databasename];
List all databases on the sql server.
mysql> show databases;
Switch to a database.
mysql> use [db name];
To see all the tables in the db.
mysql> show tables;
To see database’s field formats.
mysql> describe [table name];
To delete a database.
mysql> drop database [database name];
To delete a table.
mysql> drop table [table name];
Show all data in a table.
mysql> SELECT * FROM [table name];
Creating a new user.
# mysql -u root -p
mysql> use mysql;
mysql> INSERT  INTO user (Host,User,Password) VALUES(‘%’,'username’,PASSWORD(‘password’));
mysql> flush privileges;
Change a users password from unix shell.
#mysqladmin -u username -h hostname  -p password ‘new-password’
Change a users password from MySQL prompt. 
# mysql -u root -p
mysql> SET PASSWORD FOR  ‘user’@'hostname’ = PASSWORD(‘password’);
mysql> flush privileges;
Recover a MySQL root password.
# /etc/init.d/mysql stop
# mysqld_safe –skip-grant-tables  &
# mysql -u root
mysql> use mysql;
mysql> update user set  password=PASSWORD(“newrootpassword”) where User=’root’;
mysql> flush  privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql  start

Update a root password.
# mysqladmin -u root -p oldpassword newpassword
Allow the user “user1” to connect to the server from localhost 
# mysql -u root -p
mysql> use mysql;
mysql> grant  usage on *.* to user1@localhost identified by ‘password’;
mysql> flush  privileges;
Give user privilages for a database.
mysql> grant all privileges on  databasename.* to username@localhost;
mysql> flush privileges;
# mysql -u root -p
mysql> use mysql;
mysql> INSERT  INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv)  VALUES (‘%’,'databasename’,'username’,'Y’,'Y’,'Y’,'Y’,'Y’,'N’);
mysql>  flush privileges;.
Load a CSV file into a table.
mysql> LOAD DATA INFILE ‘/tmp/filename.csv’ replace INTO  TABLE [table name] FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’  (field1,field2,field3);
Dump all databases for backup.
#mysqldump -u root -ppassword –opt  >/tmp/alldatabases_backup.sql
Dump one database for backup.
#mysqldump -u username -ppassword –databases  databasename >/tmp/databasename.sql
Dump a table from a database.
mysqldump -c -u username -ppassword  databasename tablename > /tmp/tablename.sql
Restore database (or database table) from backup.
mysql -u username -ppassword databasename  < /tmp/databasename.sql