Monday, August 27, 2012

MySQL - 3 : Working on the Installed MySQL

Login and check the Database created in the First Post on MySQL -1


  • Go to the MySQL Workbench and find the mysql.exe
  • Login to the MySQL using the below command in the command prompt



C:\Program Files (x86)\MySQL\MySQL Workbench CE 5.2.42>mysql.exe -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

  • Now we can list the default Databases using the command,
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| world              |
+--------------------+
5 rows in set (0.00 sec)

  • To use a Database and list the tables in the Database use the below commands,
mysql> USE test;
Database changed

mysql> SHOW tables;
Empty set (0.00 sec)

mysql> USE world;
Database changed

mysql> SHOW tables;
+-----------------+
| Tables_in_world |
+-----------------+
| city            |
| country         |
| countrylanguage |
+-----------------+
3 rows in set (0.00 sec)

mysql> DESCRIBE city;
+-------------+----------+------+-----+---------+----------------+
| Field       | Type     | Null | Key | Default | Extra          |
+-------------+----------+------+-----+---------+----------------+
| ID          | int(11)  | NO   | PRI | NULL    | auto_increment |
| Name        | char(35) | NO   |     |         |                |
| CountryCode | char(3)  | NO   |     |         |                |
| District    | char(20) | NO   |     |         |                |
| Population  | int(11)  | NO   |     | 0       |                |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.03 sec)


  • Creating a Database ,table and changing the Storage engine of the created database.
mysql> create database sri;
Query OK, 1 row affected (0.01 sec)

mysql> USE sri;
Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sri                |
| test               |
| world              |
+--------------------+
6 rows in set (0.00 sec)

mysql> create table test (name varchar(20),age number);
ERROR 1064 (42000): You have an error in your SQL syntax; check
r)' at line 1
mysql> create table test (name varchar(20),age int);
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+---------------+
| Tables_in_sri |
+---------------+
| test          |
+---------------+
1 row in set (0.00 sec)

mysql>


mysql> describe test;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  |     | NULL    |       |
| age   | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> alter table test ENGINE = InnoDB;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

  • To View the available Plugins and engines,
mysql> show plugins;
+-----------------------+----------+--------------------+---------+---------+
| Name                  | Status   | Type               | Library | License |
+-----------------------+----------+--------------------+---------+---------+
| binlog                | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| mysql_native_password | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
| mysql_old_password    | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
| CSV                   | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| MEMORY                | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| MyISAM                | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| MRG_MYISAM            | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| ARCHIVE               | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| BLACKHOLE             | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| FEDERATED             | DISABLED | STORAGE ENGINE     | NULL    | GPL     |
| InnoDB                | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| INNODB_TRX            | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_LOCKS          | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_LOCK_WAITS     | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_CMP            | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_CMP_RESET      | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_CMPMEM         | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| INNODB_CMPMEM_RESET   | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
| PERFORMANCE_SCHEMA    | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| partition             | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
+-----------------------+----------+--------------------+---------+---------+
20 rows in set (0.04 sec)




In the next post will see on the structures ...

MySQL - 1 : MySQL Installation


Installing the MySQL in Windows,
Download the MySQL  Software and install it as below,
If you don't have the required softwares for MySQL to run then it will pop up the dialog box and will request you to install.











I have created one more user apart from root and given the role "DB Admin"










Completed the installation of the MySQL in Windows.









Thursday, August 23, 2012

MySQL - 2 : MYSQL Tools Installation


Installing MySQL Tools  in Windows

Download  MySQL  Tools from :  http://dev.mysql.com/downloads/gui-tools/5.0.html

For Windows :


Click on the Downloaded .msi file and follow the screenshot ,


 Accept the Agreement and click on Next 








Wednesday, August 22, 2012

ODI : Reset SUPERVISOR Password

After the Creation of the Master Repository and import of the repository zip from the different ODI Repositroy, the password of the SUPERVISOR gets set to the one of the ZIP file.
So it will pop up the below error while trying to login after the import :


oracle.odi.core.security.BadCredentialsException: Incorrect ODI username or password
at oracle.odi.core.security.SecurityManager.doODIInternalAuthentication(SecurityManager.java:392)
at oracle.odi.core.security.SecurityManager.createAuthentication(SecurityManager.java:260)
at oracle.odi.ui.docking.panes.OdiCnxFactory$1.run(OdiCnxFactory.java:214)
at oracle.ide.dialogs.ProgressBar.run(ProgressBar.java:655)
at java.lang.Thread.run(Thread.java:662)

To reset the password of the SUPERVISOR follow the below steps,

  • Login to the MREP schema in the Database.
  • Select the SNP_USER table to verify the username.
  • Using the encode.sh ,create a encrypted password.
  • Update the SNP_USER Table with the Password generated using the encode.sh for the SUPERVISOR user.
  • Now, login to the ODI GUI .

Monday, August 6, 2012

snippets - SQL Developer

A nice feature of SQL developer, SNIPPETS.





You can bring up the Snippet toolbar by clicking on
View --> Snippets













It opens the snippet toolbar at the right pane with the default snippets
The Default snippets has the queries, the functions and a lot of good options. 
Also we can add a snippet of our wish and run it whenever we want.
Its really a good tool to be used in your Sql- developer ... Try ii


Wednesday, March 21, 2012

Queries to monitor Temporary Tablespace



Temp Usage


  set linesize 120
  col v_size_GB format 99.9999
  col TABLESPACE format a15
  col USERNAME format a15

  SELECT t.USERNAME,
    t.tablespace,
    s.sid,
    spid OS_ID,
    s.serial#,
    ROUND(blocks*8192/1024/1024/1024 , 5) v_size_GB,
    s.logon_time,
    (s.last_call_et/60) Session_Time_Minutes
  FROM v$tempseg_usage t,
    v$session s,
    v$process p
  WHERE t.SESSION_ADDR=s.saddr
  AND p.addr=s.paddr;


Temp USED/FREE 



  SELECT   A.tablespace_name tablespace, D.mb_total,
           SUM (A.used_blocks * D.block_size)/1024/1024 mb_used,
           D.mb_total - 
           SUM (A.used_blocks * D.block_size)/1024/1024 mb_free
  FROM     v$sort_segment A,
           (
           SELECT   B.name, C.block_size,
                    SUM (C.bytes) / 1024 / 1024 mb_total
           FROM     v$tablespace B, v$tempfile C
           WHERE    B.ts#= C.ts#
           GROUP BY B.name, C.block_size
           ) D
  WHERE    A.tablespace_name = D.name
  GROUP by A.tablespace_name, D.mb_total;






Wednesday, March 14, 2012

Steps to recover DB (All onlinelogs lost,no valid backup)

The Method below is to help you in the case where there is you have lost all the online logs & don't have any Valid Backup :


1.  Edit the init.ora  and add :
     _allow_resetlogs_corruption=true
 
2.  Recreate control file.


3.  Recover the database
    recover database until cancel using backup controlfile;
   
4.  Open the Database with "reset logs"
     alter database open resetlogs;

5.  Immediately Take a Backup of the DB ( Exp,EXPDP,RMAN ...)


6.  Recreate the DB from the Dump.





Note : Oracle doesn't recommends the use of _ parameters unless its suggest by My Oracle Support and here we use it to get the DB back online.
Once the DB is online Take a backup and create a New one.

Thursday, February 23, 2012

ORA-01034: ORACLE not available Process ID: 0 Session ID: 0 Serial number: 0

One of the common error and below is one of the reason for this error,


In the Environment where you have more than one oracle Version ,this can happen.
If the wrong oracle home is set and if you try to login to the database of different version than the ORACLE_HOME set, you will be getting the below error.


SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 20 07:18:44 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> select count(1) from v$database;
select count(1) from v$database
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0


Set the Right ORACLE_HOME and it will solve the issue

Monday, January 30, 2012

Range values {1..n} in FOR Loop doesn't work in AIX,HP,SUN ...

The FOR Loop with range values is specially for the BASH shell.
So when you get to other OS ,if the BASH is not set then you will not be getting the expected error.


Code :

echo Shell:: $SHELL
for range in {1..3}
do
echo "Range: $range"
done;

OUTPUT :



Linux
AIX
SUN
  Shell::/bin/ksh 
  Range: 1
  Range: 2
  Range: 3
 Shell::/bin/ksh
 Range: {1..3}
 Shell::/bin/ksh
 Range: {1..3}



How to overcome this issue :

Add the "#!/bin/bash" . (find the path of the bash in other os and add it in the script.)

which bash
/usr/bin/bash

Code :

#!/usr/bin/bash
echo Shell::$SHELL
for range in {1..3}
do
echo "Range: $range"
done;


OUTPUT : AIX 

Shell::/bin/ksh
Range: 1
Range: 2
Range: 3