Tuesday, November 26, 2013

Query to find and replace a specific word in SQL Database without affecting the data along with it

update table
set column_name = replace(column_name,'TextToBeReplaced','TextToBeReplacedBy')

Mysqladmin Commands in Linux

mysqladmin is a command-line utility the comes with MySQL server and it is used by Database Administrators to perform some basic MySQL tasks easily such as setting root password, changing root password, monitoring mysql processes, reloading privileges, checking server status etc.

1.To set MySQL Root password:
# mysqladmin -u root password YOURNEWPASSWORD
 
2.to Change MySQL Root password?
#mysqladmin -u root -p123456 password 'xyz123'
 
3.To check MySQL Server is running?
# mysqladmin -u root -p ping
 
4.To Check which MySQL version I am running?
# mysqladmin -u root -p version
 
5.To Find out current Status of MySQL server?
#mysqladmin -u root -ptmppassword status 

6.To check status of all MySQL Server Variable’s and value’s?
# mysqladmin -u root -p extended-status
 
7.To see all MySQL server Variables and Values?
# mysqladmin  -u root -p variables
 
8.To check all the running Process of MySQL server?
#mysqladmin -u root -p processlist
 
9.To create a Database in MySQL server?
# mysqladmin -u root -p create databasename
 
10.To drop a Database in MySQL server?
# mysqladmin -u root -p drop databasename
 
11.To reload/refresh MySQL Privileges?
# mysqladmin -u root -p reload;
# mysqladmin -u root -p refresh;
 
The reload command tells the server to reload the grant tables. The refresh command
 flushes all tables and reopens the log files.
 
12.To shutdown MySQL server Safely?
#mysqladmin -u root -p shutdown 

other commands:
# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start
 
13.Some useful MySQL Flush commands
 
# mysqladmin -u root -p flush-hosts
# mysqladmin -u root -p flush-tables
# mysqladmin -u root -p flush-threads
# mysqladmin -u root -p flush-logs
# mysqladmin -u root -p flush-privileges
# mysqladmin -u root -p flush-status
 
 
14.To kill Sleeping MySQL Client Process?
to see: # mysqladmin -u root -p processlist
 
Run the following id with process id: 
# mysqladmin -u root -p kill 5 

15.To run multiple mysqladmin commands together?
#mysqladmin  -u root -p processlist status version 

16.To Connect remote mysql server:
# mysqladmin  -h 172.16.25.126 -u root -p
 
 
17.To execute command on remote MySQL server:
# mysqladmin  -h 172.16.25.126 -u root -p status
 
 
18.To start/stop MySQL replication on a slave server?
# mysqladmin  -u root -p start-slave
# mysqladmin  -u root -p stop-slave
 
19.To store MySQL server Debug Information to logs?
# mysqladmin  -u root -p debug
 
20.To view mysqladmin options and usage:
# mysqladmin --help 
 
 
 
Source 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Thursday, November 21, 2013

To get autorefresh resultset of Sql query

The following query does not full fill the requirements as it does not auto refresh 
the results. Each time it updates the screen with the new resultset.
 
 
 
 
SELECT GETDATE()              --your query to run
raiserror('',0,1) with nowait --to flush the buffer
waitfor delay '00:00:10'      --pause for 10 seconds
GO 5                          --loop 5 times
 
 
The above query will run  5 times, pausing for 10 seconds between each run.

Copy an existing MySQL table to a new table

To make a copy of the table tableOriginal which is in a different database called production into a new table called tableDuplicate in the currently selected database, use these two commands:

CREATE TABLE tableDuplicate LIKE production.tableOriginal ; 

INSERT into tableDuplicate SELECT * FROM production.tableOriginal ;

The first command creates the new table recipes_new by duplicating the structure of the existing table. The second command copies the data from old to new.

Tuesday, November 19, 2013

Set Java_Home and Path System variable in Windows

Stage 1. Locate the JRE Installation Directory

If you already know the installation path for the Java Runtime Environment, go to Stage 2 below. Otherwise, find the installation path by following these instructions:
  1. If you didn't change the installation path for the Java Runtime Environment during installation, it will be in a directory under C:\Program Files\Java. Using Explorer, open the directory C:\Program Files\Java.
  2. Inside that path will be one or more subdirectories such as C:\Program Files\Java\jre6

Stage 2. Set the JAVA_HOME Variable

Once you have identified the JRE installation path:
  1. Right-click the My Computer icon on your desktop and select Properties.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. Under System Variables, click New.
  5. Enter the variable name as JAVA_HOME.
  6. Enter the variable value as the installation path for the Java Development Kit.
    • If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable instead.
      Icon
      Note for Windows users on 64-bit systems
      Progra~1 = 'Program Files'Progra~2 = 'Program Files(x86)'
  7. Click OK.
  8. Click Apply Changes.
  9. Close any command window which was open before you made these changes, and open a new command window. There is no way to reload environment variables from an active command prompt. If the changes do not take effect even after reopening the command window, restart Windows.




You can run Java applications just fine without setting the PATH environment variable. Or, you can optionally set it as a convenience.
Set the PATH environment variable if you want to be able to conveniently run the executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
C:\Java\jdk1.7.0\bin\javac MyClass.java
The PATH environment variable is a series of directories separated by semicolons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should have only one bin directory for the JDK in the path at a time (those following the first are ignored), so if one is already present, you can update that particular entry.
The following is an example of a PATH environment variable:
C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem
It is useful to set the PATH environment variable permanently so it will persist after rebooting. To make a permanent change to the PATH variable, use the System icon in the Control Panel. The precise procedure varies depending on the version of Windows:
Windows XP
  1. Select Start, select Control Panel. double click System, and select the Advanced tab.
  2. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  3. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows Vista:
  1. From the desktop, right click the My Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced tab (Advanced system settings link in Vista).
  4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows 7:
  1. From the desktop, right click the Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced system settings link.
  4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

For Details