Saturday 20 September 2014

ERROR 2002 (HY000): Can't connect to local MySQL server.

Are you are getting following error while running MySQL server?


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)


Simply follow these steps:-

-Go to MySQL directory
   root@localhost:[/]cd /var/lib/mysql
   root@localhost:[/var/lib/mysql]

-Rename mysql.sock file to mysql.sock_old
   root@localhost:[/var/lib/mysql]mv mysql.sock mysql.sock_old

-Restart MySQL server.
   root@localhost:[/var/lib/mysql]service mysqld restart
      OR
    root@localhost:[/var/lib/mysql]/etc/init.d/mysqld restart

Thursday 18 September 2014

Get MySQL Table Creation Time.

How to check table create,update,check time in MySQL?


You can check table creation,update,check time for any table. Find below.

If you want to check the last update time or create time or last check time of table use following query for the above.

Syntax:- SELECT CREATE_TIME,UPDATE_TIME,CHECK_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME='table_name' ;

Also you can check following for any table.

TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
TABLE_TYPE
ENGINE
VERSION
ROW_FORMAT
TABLE_ROWS
AVG_ROW_LENGTH
DATA_LENGTH
MAX_DATA_LENGTH
INDEX_LENGTH
DATA_FREE
AUTO_INCREMENT
CREATE_TIME
UPDATE_TIME
CHECK_TIME
TABLE_COLLATION
CHECKSUM
CREATE_OPTIONS
TABLE_COMMENT
TABLESPACE_NAME






Wednesday 17 September 2014

Create MySQL User and Grant Permission

Create MySQL user and grant permission


Here we learn, how to create MySQL user?

Suppose we want to create user Danish and want to full access on MySQL Databases/tables from any IP.

Syntax to create user:- CREATE USER '< user name >'@'< password >' IDENTIFIED BY
Syntax to grant permission:- GRANT < permission > ON < database >.< table > WITH GRANT OPTION

Following is an example of above.

 CREATE USER 'danish'@'*' IDENTIFIED BY 'danish';

 GRANT ALL PRIVILEGES ON student.login TO 'danish'@'*' WITH GRANT OPTION;

In above example we have created a user with name danish, this user can only access login table in student database and can perform all operations on login table.

You can assing a specific domain/ip for MySQL user danish to access MySQL. Find below.

 CREATE USER 'danish'@'255.255.255.255' IDENTIFIED BY 'danish';

 GRANT ALL PRIVILEGES ON student.login TO 'danish'@'255.255.255.255' WITH GRANT OPTION;


You can grant all database access with all tables. Find Below.


 CREATE USER 'danish'@'255.255.255.255' IDENTIFIED BY 'danish';

 GRANT ALL PRIVILEGES ON *.*TO 'danish'@'255.255.255.255' WITH GRANT OPTION;


Following are the privileges and their meaning in MySQL.


Tuesday 16 September 2014

How to set auto-logout time for SSH sessions RHEL

Set auto logout for SSH session.


If you want to set timeout for user sessions on your Linux machine, you can use the variable TMOUT. You can set a value for TMOUT in bash_profile or bashrc file.

# auto-logout if the shell session is idle for 1 hour
TMOUT=3600

Saturday 13 September 2014

Easy Way: Java

Easy Way: Java: Write a program to addd two integer without using + or any arithmetic operator public static int get_sum(int a, int b){  if(b==0) retur...

Want to copy files/directories from one server to another using SSH?

Want to copy files/directories from one server to another using SSH?


Following are two way to copy files/directories from one server to another server over SSH.

Copy content from a directory:

scp -P < SSH port number of remote server> < files path on local server> < ip/host of remote server>:< path to copy files/directories>

e.g. scp -P 22 /home/xyz.zip www.example.com:/home/cfile/

Copy content from directory and the contents of any directory inside that directory

scp -P < SSH port number of remote server> -r < files path on local server> < ip/host of remote server>:< path to copy files/directories>

e.g. scp -P 22 -r /home/cpfiles/ www.example.com:/home/cfile/


Linux : could not start the session due to some internal error

What is next if your Linux OS is unable to boot with following error?


Error: could not start the session due to some internal error

To remove above error message follow following steps:-

Try turning off selinux at boottime

  -When the grub splash screen is displayed press any key
  -Select the Linux boot choice and press the 'e' key
  -Select the kernel line and press the 'e' key again
  -At the end of the line add a space followed by selinux=0
  -When done press the 'Enter' key followed by the 'b' key

MySQL Process

How to kill all MySQL sleep process.

If you want to kill all sleep process in MySQL go to MySQL terminal and follow:-


mysql >select concat('KILL ',id,';') FROM information_schema.processlist where user='root' into outfile '/tmp/xyz.txt';
mysql> source /tmp/zyz.txt;​

Thursday 11 September 2014

Linux(RHEL)

Unable to kill process with command


If you are unable to kill any process in linux with kill command please use following.

kill -9 [process id]

e.g. kill -9 4534

MySQL

Some errors and their solutions in MySQL.


ERRO(2006): MySQL server gone away

To avoid this error set the max-allowed-packet of MySQL global variable.

mysql> set global set max_allowed_packet =10000000;

MySQL Dump on windows.

Suppose your mysql is installed at following directory, and username of mysql is root and password is blank then:-

Bin directory- C:\Program Files\MySQL\MySQL Server 5.1\bin

-Open command prompt and got the bin directory of mysql.
-Use the following command syntax to take the dump of mysql database of table.

mysqldump --user= --password= >path to directory

e.g. mysqldump database --user=root --password= >D:\\db.sql




Wednesday 10 September 2014

Java



Write a program to addd two integer without using + or any arithmetic operator


public static int get_sum(int a, int b){

 if(b==0) return a;

 int sum = a^b; //add without carry

 it carry = (a&b)<<1; //carry,but don't add


 return get_sum(sum,carry);


}




Write a program to swap two integer without using third variable or any arithmetic operator



public static void main(String[] args){

//Supose there are two int a=5 b=4

int a = 5; /*a=100*/
int b = 4; /*b=101*/
a=a^b; /* 100^101 = 001*/
b=a^b; /* 001^101 = 100*/
a=a^b; /*001^100 = 101*/

System.out.println("Value of a="+a);
System.out.println("Value of a="+a);

}


Enable 'HTML Manager'- Apache Tomcat

 Enable 'HTML Manager'- Apache Tomcat Go to Apache-tomcat's home directory and edit the tomcat-users.xml ${apache_home}/conf/tom...