Sunday 10 June 2012

What is Swap Space?

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.


The size of your swap should be equal to twice your computer's physical RAM for up to 2 GB of physical RAM. For physical RAM above 2 GB, the size of your swap should be equal to the amount of physical RAM above 2 GB. The size of your swap should never less than 32 MB


Using this basic formula, a system with 2 GB of physical RAM would have 4 GB of swap, while one with 3 GB of physical RAM would have 5 GB of swap
To remember:
File systems and LVM2 volumes assigned as swap space cannot be in use when being modified. For example, no system processes can be assigned the swap space, as well as no amount of swap should be allocated and used by the kernel. Use the free and cat /proc/swaps commands to verify how much and where swap is in use.



Adding Swap Space

You have three options: create a new swap partition:
1. Create a new swap file.
2. Extend swap on an existing LVM2 logical volume.
3. Creating an LVM2 Logical Volume for Swap.


1. Creating a Swap File:
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
# dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:
# mkswap /swapfile
To activate the swap file:
# swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
The next time the system boots, it enables the new swap file.
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.


2. Extend swap on an existing LVM2 logical volume.
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 256 MB:
# lvm lvresize /dev/VolGroup00/LogVol01 -L +256M
 Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -va
Test that the logical volume has been extended properly:
# cat /proc/swaps
# free


3. Creating an LVM2 Logical Volume for Swap. Create the LVM2 logical volume of size 256 MB: #lvm lvcreate VolGroup00 -n LogVol02 -L 256M Format the new swap space: # mkswap /dev/VolGroup00/LogVol02 Add the following entry to the /etc/fstab file: /dev/VolGroup00/LogVol02 swap swap defaults 0 0 Enable the extended logical volume: # swapon –va Test that the logical volume has been extended properly: # cat /proc/swaps

MYSQL


1. HOW TO INSTALL MYSQL ON RHEL5

[root@training ~]# yum install mysql-server mysql

[root@training ~]# service mysqld restart
[root@training ~]# chkconfig mysqld on

2. TO MAKE ADMIN USER IN MYSQL

[root@training ~]# mysqladmin -u root password PASS@123
[root@training ~]# mysql -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

  3. TO CHECK CURRENT VERSION

mysql> SELECT VERSION();      

+-----------+
| VERSION() |
+-----------+
| 5.0.45    |
+-----------+
1 row in set (0.00 sec)

4.TO CHECK CURRENT DATE

mysql> SELECT CURRENT_DATE();  
+----------------+
| CURRENT_DATE() |
+----------------+
| 2012-06-09     |
+----------------+
1 row in set (0.00 sec)

5. TO RUN MULTI COMMAND IN ONE QUERY 

mysql> SELECT VERSION(), CURRENT_DATE;

+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 5.0.45    | 2012-06-09   |
+-----------+--------------+
1 row in set (0.00 sec)

6. TO USE MYSQL AS A CALCULATER

mysql> select (4-5)*5;
+---------+
| (4-5)*5 |
+---------+
|      -5 |
+---------+
1 row in set (0.00 sec)

7. TO CHECK TIME WITH DATE

mysql> select now();  
+---------------------+
| now()               |
+---------------------+
| 2012-06-09 22:29:35 |
+---------------------+
1 row in set (0.00 sec)

7. TO RUN THE STATEMENT IN MULTIPLR LINE

mysql> SELECT USER()        
    -> ,
    -> CURRENT_DATE
    -> ;
+----------------+--------------+
| USER()         | CURRENT_DATE |
+----------------+--------------+
| root@localhost | 2012-06-09   |
+----------------+--------------+
1 row in set (0.00 sec)

8. TO CANCEL AN CURRENT COMMAND, PRESS SMALL \C

mysql> select user
    -> ()
    -> \c
mysql>

9. TO CHECK DATABASE INSIDE MYSQL

mysql> SHOW DATABASES;  
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

10. TO ACCESS THE DATABASE

mysql> USE test  
Database changed
mysql>

11. HOW TO CREATE DATABASE 

mysql> CREATE DATABASE example._db;
Query OK, 1 row affected (0.02 sec)

mysql>

12. TO GIVE PRIVILEGE FOR  USER ON A PARTICULLAR DATABASE

mysql> grant CREATE,INSERT,DELETE,UPDATE,SELECT on example_db.* to user@localhost;
Query OK, 0 rows affected (0.00 sec)

13. TO CREATE USER WITH PASSWORD

mysql> CREATE USER 'USER'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

14. TO REMOVE/DROP USER IN MYSQL

mysql> drop user dev@localhost;          
Query OK, 0 rows affected (0.00 sec)


 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes