Saturday 25 July 2015

Mysql Backup and Restore command for linux


Backup MySQL DB
In order to take a backup of MySQL database,first you need to make sure that required database is present in database server and you have a required access to it.

The following command is used to take an backup:

mysqldump -u[username] -p[password] [database name] > [file name.sql]

for ex: mysqldump -uroot -prootDB mydb>/exports/db/mysql.sql


If you want to take an backup of all databases present in database server,then use following command:

mysqldump -uroot -prootDB --all-databases>/exports/db/allmysql.sql


To take a backup of mysql procedures ,functions along with tables,use this command:

mysqldump -uroot -prootDB --routines mydb>/exports/db/mysql.sql

Restore MySQL DB

To restore the database use this command:

mysql -u[username] -p[password] [database name] < [file name.sql]

for ex: mysql -uroot -prootDB mydb</exports/db/mysql.sql



In case of any doubt,please post a question.







Java Program to count number of 0's and 1's in n*n matrix




Given a matrix which contains only 0's and 1's .We need to count the number of occurrences of zeroes and ones in it.Its a very simple program but we get confused when it is asked by someone else and we start looking for complex solutions.


Hers is the implementation:-



 import java.util.Scanner;  
 /**  
  *   
  */  
 /**  
  * @author Dixit  
  *   
  */  
 public class SampleMatrix {  
      public static void main(String args[]) {  
           int m, n,i,j;  
           int sum=0;  
           Scanner in = new Scanner(System.in);  
           System.out.println("Enter the number of rows and columns of matrix");  
           m = in.nextInt();  
           n = in.nextInt();  
           int first[][] = new int[m][n];  
           System.out.println("Enter the elements of first matrix");  
           for (i = 0; i < m; i++)  
                for (j = 0; j < n; j++)  
                     first[i][j] = in.nextInt();  
           for (i = 0; i < m; i++)  
                for (j = 0; j < n; j++)  
                     sum = sum+first[i][j] ;   
           System.out.println(" Count of number of 1's in the matrix:-"+sum);  
           System.out.println(" Count of number of 0's in the matrix:-"+(m*n-sum));  
      }  
 }  


Difference between HashMap and ConcurrentHashMap



HashMap and ConcurrentHashMap are two different types of hashMap in java.Both implements Map interface but their internal working is different.


                                                     HashMap Vs ConcurrentHashMap



               HashMap


              ConcurrentHashMap
Null Value/Key


 It allow null value as well as key.
 It does not allow null values and keys.
 Thread Safe 


No.In order to make hashmap thread safe we need to use Collections.synchronized(Map) method
 Yes


Concurrency
 It does not allow concurrent access to multiple threads
 It allows a very high level of concurrency. Multiple threads can work on different portion of ConcurrentHashMap


 Iterator
 It implements fail fast.
 It implements fail safe.







Study internal working of both types of hashMap .It’s very important concept asked in interviews.