Regular Expression for IP Validation

Here is the regular expression for IP validation

“^([01]?\\d\\d?|2[0-4]\\d|25[0-4])\\.” +
“([01]?\\d\\d?|2[0-4]\\d|25[0-4])\\.” +
“([01]?\\d\\d?|2[0-4]\\d|25[0-4])\\.” +
“([01]?\\d\\d?|2[0-4]\\d|25[0-4])$”

this will work for range till 255.255.255.255

you can use this javascript validation with regular expression.

jQuery required validation

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" 
src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
jQuery.validator.setDefaults({
	debug: true,
	success: "valid"
});;
</script>

  <script>
  $(document).ready(function(){
    $("#myform").validate({
  rules: {
    fruit: "required"
  }
});
  });
  </script>
  <style>#fruit { margin-left: .5em; float: left; }
  	#fruit, label { float: left; font-family: Arial, Helvetica, sans-serif; font-size: small; }
	br { clear: both; }
	input, select { border: 1px solid black; margin-bottom: .5em;  }
	select.error { border: 1px solid red; }
	label.error {
		background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/unchecked.gif') no-repeat;
		padding-left: 16px;
		margin-left: .3em;
	}
	label.valid {
		background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/checked.gif') no-repeat;
		display: block;
		width: 16px;
		height: 16px;
	}
</style>
</head>
<body>

<form id="myform">
  <label for="fruit">Please select a fruit</label>
  <select id="fruit" name="fruit" title="Please select something!"
    <option value=""></option>
    <option value="1">Banana</option>
    <option value="2">Apple</option>
    <option value="3">Peach</option>
  </select>
  <br/>
  <input type="submit" value="Validate!" />
</form>

</body>
</html>

you can use this for any input validation.
Its very easy...use it,,,,,,!!!!!!!!!!!!!1111

Show and Hide DIV using javascript

<html>
<head>

<script language=”JavaScript” type=”text/javascript”>
function Test(rad){
var rads=document.getElementsByName(rad.name);
document.getElementById(‘courier’).style.display=(rads[1].checked)?’none’:’none’;
document.getElementById(‘courier’).style.display=(rads[1].checked)?’block’:’none’;
}
</script></head>

<body>
<input name=”selection” type=”radio”  onclick=”Test(this);”/>
<input name=”selection” type=”radio”  onclick=”Test(this);”/>

<div id=”courier”>Select your courier:<br />
Blah blah….Dropdown to come here</div>

</body>

</html>

when you load the page nothing will be selected.

but when you select first radio button it will hide the div and when  second radio button selected it will show the div.

you can use this for table hide .

its so simple with javascript.

Try this ……..!!!!!!!!!!!

 

 

 

 

Master-Slave Replication Mysql on CentOS and RHEL

Mysql replication is to replicate database from one server to another.
Master – Slave replication is that where one server is master and another is slave, and when you make any change in master database than the slave server automatically will get updated.
This works on RHEL5 and CentOS6.

Here i have made very simple steps to create master-slave replication of mysql.

suppose i have two servers
Server1:192.168.0.1
Server2:192.168.0.2

first of all install mysql and mysql-server on both servers

#yum install mysql mysql-server

than start the mysql service

#/etc/init.d/mysqld start

now edit the file /etc/my.cnf on Server1

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1

[mysqld]
server-id=1
binlog-do-db=db(database name that you want to replicate)
log-bin=mysql-bin
innodb_flush_log_at_trx_commit=1
sync_binlog=1

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

and restart mysql service
#/etc/init.d/mysqld restart

now edit the file /etc/my.cnf on Server2

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
old-password=1

[mysqld]
server-id=2
master-host=192.168.0.1(ip of master or server1)
master-connect-retry=60
master-user=root(user that you have created in master)
master-password=root(password that you have given to the master user)
replicate-do-db=db(database name that you want to replicate)

log-bin=mysql-bin
innodb_flush_log_at_trx_commit=1
sync_binlog=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

and restart the mysql service
#/etc/init.d/mysqld restart

now on Server1
write this commands
#mysql -u root -p(password for mysql if you have set)
#GRANT REPLICATION SLAVE ON *.* TO ‘username’@’192.168.0.2’ IDENTIFIED BY ‘password’;
#show master status;
when you write show master status; command you will see output like this
+—————+———–+————–+——————+
| File          | Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+—————+———–+————–+——————+
| binlog.000005 | 849349769 |        db    |                  |
+—————+———–+————–+——————+
1 row in set (0.00 sec)

now on Server2
write this commands
#mysql -u root -p(password for mysql if you have set)
#CHANGE MASTER TO
MASTER_HOST=’192.168.0.1(ip of server1)’,
MASTER_USER=’username(user of master)’,
MASTER_PASSWORD=’password(password of master)’,
MASTER_LOG_FILE=’binlog.000005′,
MASTER_LOG_POS=849349769;
#GRANT REPLICATION SLAVE ON *.* TO ‘username’@’192.168.0.1’ IDENTIFIED BY ‘password’;
#use database(database name)
#start slave;
#show slave status;
from above command you will find output like this

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.1
Master_User: (username of master)
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 259
Relay_Log_File: mysqld-relay-bin.000005
Relay_Log_Pos: 404
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: db
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 259
Relay_Log_Space: 705
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)

if you get output as above than you have configured correctly

now to check that replication is working or not
do this on server1

mysql> create database tecmint;
mysql> use tecmint;
mysql> CREATE TABLE employee (c int);
mysql> INSERT INTO employee (c) VALUES (1);
mysql> SELECT * FROM employee;

on server2
mysql> SELECT * FROM employee;

Try this out……
i refered many sites but i was getting problem
now i have made this more easy
Enjoy this…………….!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Get back Deleted root@localhost account in MySQL

Today i was working with mysql and i added mysql users in user table , while deleting i deleted the root user….!!!

ooops this is now the problem that how to login to mysql???

i found the solution over here..

Follow this steps to get back your deleted root user

  1. service mysqld stop
  2. su – mysql
  3. mysqld_safe --skip-grant-tables &
  4. mysql
  5. use mysql
  6. INSERT INTO user VALUES
    ('localhost','root',password('passwd'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
    INSERT INTO user VALUES
    ('127.0.0.1','root',password('passwd'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
  7. commit;
  8. FLUSH PRIVILEGES;
  9. exit
  10. killall mysqld
  11. /etc/init.d/mysql start

You can confirm that the root account has been created (or is indeed missing!) by listing entries on the user table:
use mysql;
select Host,User from user;

Try this out…!!!!!!!!!!!!!!!!!!!!!!