Search This Blog

Wednesday 30 March 2016

​ To reset the password

Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):
  1. Stop mysql

    sudo /etc/init.d/mysql stop

    or for other distro versions

    sudo /etc/init.d/mysqld stop
  2. Start MySQL in safe mode

    sudo mysqld_safe --skip-grant-tables &
  3. Log into MySQL using root

    mysql -uroot
  4. Select the MySQL database to use

    use mysql;
  5. Reset the password

    update user set password=PASSWORD("mynewpassword") where User='root';
  6. Flush the privileges

    flush privileges;
  7. Restart the server

    quit
  8. Stop and start the server again

    ubuntu and debian

    sudo /etc/init.d/mysql stop  ...  sudo /etc/init.d/mysql start

    On CentOS and Fedora and RHEL

    sudo /etc/init.d/mysqld stop  ...  sudo /etc/init.d/mysqld start
  9. Login with new password

    mysql -u root -p
  10. Type new password and enjoy your server again like nothing happened

Monday 14 March 2016

Difference between DDL, DML and DCL commands?

DDL

Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
  • CREATE - to create objects in the database
  • ALTER - alters the structure of the database
  • DROP - delete objects from the database
  • TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT - add comments to the data dictionary
  • RENAME - rename an object

DML


Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
  • SELECT - retrieve data from the a database
  • INSERT - insert data into a table
  • UPDATE - updates existing data within a table
  • DELETE - deletes all records from a table, the space for the records remain
  • MERGE - UPSERT operation (insert or update)
  • CALL - call a PL/SQL or Java subprogram
  • EXPLAIN PLAN - explain access path to data
  • LOCK TABLE - control concurrency

DCL


Data Control Language (DCL) statements. Some examples:
  • GRANT - gives user's access privileges to database
  • REVOKE - withdraw access privileges given with the GRANT command

TCL


Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
  • COMMIT - save work done
  • SAVEPOINT - identify a point in a transaction to which you can later roll back
  • ROLLBACK - restore database to original since the last COMMIT
  • SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

Wednesday 9 March 2016

Oracle Start&Stop script

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

# Source function library.

. /etc/rc.d/init.d/functions

ORACLE_HOME=/app/oracle/product/11.2.0/dbhome_1
ORACLE_OWNER=oracle

if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi

case "$1"  in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
       echo -n $"Starting Oracle DB:"
        su - $ORACLE_OWNER  -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
        echo "Oracle started"
        echo   `emctl start dbconsole`
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORACLE_OWNER
        echo   `emctl stop dbconsole`
       echo   `$ORACLE_HOME/bin/dbshut $ORACLE_HOME`
   
       echo "Done"
        ;;
*)
echo $"Usage: $0 {start|stop}"
esac

Tuesday 8 March 2016

Linux Force DHCP Client (dhclient) to Renew IP Address

You need to use Dynamic Host Configuration Protocol Client i.e. dhclient command. The client normally doesn't release the current lease as it is not required by the DHCP protocol. Some cable ISPs require their clients to notify the server if they wish to release an assigned IP address.

The dhclient command, provides a means for configuring one or more network interfaces using the Dynamic Host Configuration Protocol, BOOTP protocol, or if these protocols fail, by statically assigning an address.

Linux renew ip command

The -r flag explicitly releases the current lease, and once the lease has been released, the client exits. For example, open terminal and type the command:
$ sudo dhclient -r
Now obtain fresh IP:
$ sudo dhclient

How can I renew or release an IP in Linux for eth0?

To renew or release an IP address for the eth0 interface, enter:
$ sudo dhclient -r eth0
$ sudo dhclient eth0

In this example, I am renewing an IP address for my wireless interface:

   sudo dhclient -v -r eth0  sudo dhclient -v eth0  

Sample outputs:

Fig.01: Renew DHCP address example

Fig.01: Renew DHCP address example

The -v option shows information on screen about dhcp server and obtained lease.

Other options in Linux to renew dhcp

There is no need to restart network service. Above command should work with any Linux distro such as RHEL, Fedora, CentOS, Ubuntu and others. On a related note you can also try out the following commands:
# ifdown eth0
# ifup eth0
### RHEL/CentOS/Fedora specific command ###
# /etc/init.d/network restart

OR
### Debian / Ubuntu Linux specific command ###
# /etc/init.d/networking restart

nmcli command (NetworkManager) to renew IP address in Linux

The NetworkManager daemon attempts to make networking configuration and operation as painless and automatic as possible by managing the primary network connection and other network interfaces, like Ethernet, WiFi, and Mobile Broadband devices command-line tool for controlling NetworkManager. The nmcli is a command-line tool for controlling NetworkManager and getting its status. To renew IP address using nmcli for connection named 'nixcraft_5G' (use 'nmcli con' command to get list of all connections):

   nmcli con  nmcli con down id 'nixcraft_5G'  nmcli con up id 'nixcraft_5G'  

Sample outputs:

Fig.02: nmcli command in action

Configuring ODBC Data Sources (Linux(R), UNIX(R)) (Step by Step)

After you install IBM Information Server, you need to configure the WebSphere DataStage ODBC connections.

Log in through putty on server using Administrator User name and Password. 1 thing to remember that log in user should have SUDO rights.
My suggestion here is that you use WINSCP to find or edit these three files instead of Putty.
About this task
You need to edit three files to set up the required ODBC connections. These are:

  • dsenv
  • .odbc.ini ( Note that this file is .odbc.ini not only odbc.ini
  • uvodbc.config

All three are located in the $DSHOME directory. Copies of uvodbc.config are also placed in the project directories.

Simplest path to find these three files is

/opt/IBM/InformationServer/Server/DSEngine

My suggestion here is that you use WINSCP to find or edit these three files instead of Putty.

What are wired and non-wired Protocol drivers?

Non-Wire protocol drivers VS Wire protocol drivers

Basically there are two type of ODBC drivers being used in DataStage:

non-wire protocol drivers – require  database client software to be installed on the DataStage server (the drivers use the API supplied by the database client)

wire protocol drivers – do not require database client software (they communicate with the database directly)

Non-wire drivers require different setup information than wire drivers. Non-wire drivers require information about the location of the database client software. Wire drivers require information about the database itself.
For information about configuring the ODBC environment for your specific database, see the Data Direct Drivers Reference manual odbcref.pdf file located in the$DSHOME/Server/branded_odbc/books/odbc directory. You should also check the ODBCREAD.ME file in the branded_odbc directory. There is also an html file located in branded_odbc/odbchelp.

  • dsenv file
    The WebSphere DataStage server has a centralized file for storing environment variables called dsenv in $DSHOME. $DSHOME identifies theWebSphere DataStage installation directory. The default directory is /opt/IBM/InformationServer/Server/DSEngine.
  • .odbc.ini file
    The .odbc.ini files gives information about connecting to the database (wire protocol drivers) or the database client (non-wire protocol drivers). If your system uses a mix of drivers, your .odbc.ini file will contain a mix of entry types.
  • uvodbc.config file
    Use the uvodbc.config file to specify the DSNs for the databases that you are connecting to through ODBC.
  • Creating and binding a DB2 package to a DSN
    Before you connect to a DB2 DSN you need to bind DB2 packages to the DSN. You must bind a package to every DSN you are going to use to connect to a DB2 database.
  • Configuring third party ODBC drivers
    You can use ODBC drivers from third parties for connecting WebSphere DataStage to different data sources. You might require to connect to a database not supported by the Data Direct driver pack, for example, Redbrick. You can use only one ODBC driver manager at a time. As a result, you cannot use third party drivers at the same time that you use the WebSphere DataStage drivers, and you must perform some reconfiguration to switch between the two types.

dsenv file

The WebSphere DataStage server has a centralized file for storing environment variables called dsenv in $DSHOME. $DSHOME identifies the WebSphere DataStage installation directory. The default directory is /opt/IBM/InformationServer/Server/DSEngine.
You might need to add new environment variables as you configure WebSphere DataStage to connect to different databases using plug-ins or ODBC drivers. Any environment variables you need for interactive use of ODBC drivers to make a connection to an ODBC data source must be added to the dsenv file. This lets the WebSphere DataStage server inherit the proper environment for ODBC connections.
For a connection using a wire protocol driver, there are no changes required to dsenv.
For a connection using a non-wire protocol driver, you generally need to specify the following information in the dsenv file:

  • environment variables required by the database client software
  • database home location
  • database library directory
  • the PATH environment variable

The following table shows the library path environment variables for each operating system.

Table 1. Library path environment variables for WebSphere® DataStage®
Operating system Environment variables
AIX® LIBPATH
Linux® LD_LIBRARY_PATH
Solaris LD_LIBRARY_PATH

The following example shows some typical entries for commonly used databases.
#Sybase 11 setupLANG=Export LANGSYBASE=/export/home/sybase/sybase;export SYBASELD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SYBASE/lib:/usr/lib:/lib;export LD_LIBRARY_PATH# Oracle 9iORACLE_HOME=/space/oracle9iLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib;export LD_LIBRARY_PATHORACLE_SID=WSMK5export ORACLE_HOME ORACLE_SID#Informix XPS 9.3INFORMIXDIR=/space/informix; export INFORMIXDIRINFORMIXSERVER=solnew2.1;export INFORMIXSERVERONCONFIG=onconfig.solnew2; export ONCONFIGLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/cli;export LD_LIBRARY_PATHLANG=Cexport LANG#DB2 Version 9DB2DIR=/opt/IBM/InformationServer/DB2;export DB2DIRDB2INSTANCE=DB2inst1; export DB2INSTANCEINSTHOME=/export/home/DB2inst1;export INSTHOMEPATH=$PATH:$INSTHOME/sqllib/bin:$INSTHOME/sqllib/adm:$INSTHOME/sqllib/miscexport PATHLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INSTHOME/sqllib/lib;export LD_LIBRARY_PATHTHREADS_FLAG=native;export THREADS_FLAG

Stop and restart the WebSphere DataStage server whenever you edit dsenv.

uvodbc.config file

Use the uvodbc.config file to specify the DSNs for the databases that you are connecting to through ODBC.

Entries in uvodbc.config have the following form:

<name> DBMSTYPE = ODBC

name is the ODBC data source name (DSN), this should be the same name as specified in the .odbc.ini file. The spaces on either side of the equal sign are required.

The following example shows a typical uvodbc.config file:

[ODBC DATA SOURCES] <localuv>DBMSTYPE = UNIVERSEnetwork = TCP/IPservice = uvserverhost = 127.0.0.1<Sybase1>DBMSTYPE = ODBC<Sybase2>DBMSTYPE = ODBC<Oracle8>DBMSTYPE = ODBC<Informix>DBMSTYPE = ODBC<DB2>DBMSTYPE = ODBC

A copy of the uvodbc.config file is also placed in each WebSphere DataStage project directory. For example, the default path for projects on Linux® is/opt/IBM/WDIS/Server/Projects/. This is useful where you configure a data source that is known to some projects but not others. By default, WebSphere DataStage searches the current project directory for a uvodbc.config file and, if it finds one, uses this in preference to the file in $DSHOME. If you alteruvodbc.config after creating projects you should copy the edited file to the project directories.

.odbc.ini file

The .odbc.ini files gives information about connecting to the database (wire protocol drivers) or the database client (non-wire protocol drivers). If your system uses a mix of drivers, your .odbc.ini file will contain a mix of entry types.

Configuration examples for the various platforms are provided in $DSHome/branded_odbc/IBM_Tools in the odbc.ini file.

  • aix_4.2.odbc.ini for AIX® systems.
  • sun_4.2.odbc.ini for Solaris systems.
  • linux_4.2.odbc.ini for Linux® systems.

These files give the minimum parameter settings required to create a working odbc.ini file. They each give configurations for the following databases:

  • DB2® on Linux, UNIX®, Windows®, and AS400
  • Oracle on Linux and UNIX
  • Informix® on Linux, UNIX, and Windows
  • Microsoft® SQL Server 2000 connection
  • Sybase on Windows

Apache tomcat Auto Startup script linux

#!/bin/bash
# chkconfig:
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_26
export JAVA_HOME
TOMCAT_HOME=/opt/tomcat/bin
START_TOMCAT=/opt/tomcat/bin/startup.sh
STOP_TOMCAT=/opt/tomcat/bin/shutdown.sh
start() {
echo -n "Starting tomcat: "
cd $TOMCAT_HOME
${START_TOMCAT}
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
cd $TOMCAT_HOME
${STOP_TOMCAT}
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0

Extending A Linux Disk With LVM – Extending Root Partition

A quick tutorial of something I did today. We use vmware here a lot and instead of installing an OS each time a VM is requested, we have operating systems installed on VM templates "ready-to-go" and then deploy the template to a VM per request.

As you can guess, the VM templates are "minimal" on resources (including disk space) so when we get a VM request, we often have to extend the root partition per the user requirement.

So here are my exact steps (no cutting anything out) using the LVM (Logical Volume Manager) commands to extend a root disk. OS is Centos 6.3 a.k.a. Redhat 6.3 on a VM.

NOTE: If you are not using a VM but a physical server and adding disks to the chassis or via a SAN, all the commands are the same, you'd just be using different disk devices like /dev/sdb, or /dev/sdc, and the like.

extending root partition using lvm on linux

A few terms

PV = Physical Volume. When you add a new disk or new partition, you need to designate it as a PV so it can be used by the LVM
VG = Volume Group. This is a group of PVs
LV = Logical Volume. This is an abstraction of disk space carved out from a Volume Group (VG) which the OS can then use just as it would a regular hard drive
PE = Physical Extents. Think of this like "blocks". When you do a "vgdisplay" you will see the PE size (mine was 4mb), the total number of PE's in the VG and the free PEs available. With some multiplication you would calculate out the total size of the VG and the total free space available on the VG.

Here are my exact linux commands in a nutshell:

# df -h
To see the current disk usage
# fdisk -l
To see the current partitioning
# poweroff
Turn the VM off so we can extend the disk on the VM side. For physical servers you would just be adding a new SAS/SATA disk to the chassis or adding a LUN on a SAN and presenting it which does *not* necessarily require a poweroff

Intermission to add new disk and power on if necessary

# fdisk -l
To see the new disk size on /dev/sda which we just extended, or to see new disks we just presented (/dev/sdb, /dev/sdc, etc.)
# fdisk /dev/sda
To create new partitions for the OS to use. These new partitions will be added to the VG so we can extend the LV that the "/" partition is on. My newly created partition in the example is /dev/sda3. For new disks you would use /dev/sdb, or /dev/sdc. If you are using an extended /dev/sda like in my case, you will need to reboot for the changes to be seen
# fdisk -l
To see the new partitions
# pvdisplay
View current physical volumes a.k.a. pv
# pvcreate /dev/sda3
Allow Linux OS to use the new partition in LVM
# pvdisplay
See the new pv /dev/sda3
# vgdisplay
View the current volume groups
# vgextend vg_cents6364bit /dev/sda3
Add the new PV /dev/sda3 to the existing VG vg_cents6364bit
# vgdisplay
Now you can see the new size of the VG vg_cents6364bit. Note the new amount of free PE's (physical extents)
# lvdisplay
View the current LV. In my example, /dev/vg_cents6364bit/lv_root which is the root partition
# lvextend -l +2559 /dev/vg_cents6364bit/lv_root
Now make the LV larger. Growing the LV /dev/vg_cents6364bit/lv_root by 2559 PEs
# lvdisplay
Now you can see the larger size of the LV
# resize2fs /dev/vg_cents6364bit/lv_root
Online resize of the actual filesystem now on that LV
# df -h
You can see the new size now using the "df" command