Wednesday, 19 October 2016

How can we use federated engine in MySql

Federated engine is sync between database table of two servers. It's very useful for small load or some tables, not used for like cluster.

We can use federated engine in MySql, but it is default disable.

Step 1:
Execute "SHOW ENGINES" in MySql

















Step 2:
Changes in my.ini mysql file

write federated below mysqld in my.ini file.

[mysqld]
federated

Step3:
Restart MySql service

Step 4:
Table should be like a below mentioned.

CREATE TABLE table_name(id int(10),name varchar(10))
ENGINE=FEDERATED
DEFAULT CHARSET=utf8
CONNECTION='mysql://server_db_user_name:server_db_password@server_ip:server_port/db_name/table_name';

server_db_user_name is mysql db user name
server_db_password is mysql db password
server_ip is DB Host server
server_port is default 3306
db_name is database name
table_name is where you are sync.

Cheers!!!

Thursday, 8 September 2016

Enable or Disbale Triggers in MySql

In MySql, you can be enable/disable triggers whenever you want. Just simply follows below guidelines.
Step 1
write the below these lines instead of "begin" in trigger before sql statement every time when you will create the trigger.

thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE) OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE)) AND (USER() = 'username@host') THEN
    LEAVE thisTrigger;
END IF;

username such as root, username(if you are created user)
host such as localhost, ip of server, etc.


Step 2
 Whenever you want the enable or disable triggers then use below query in MySql.

1. If you want disable all Before Insert triggers.
SET @TRIGGER_BEFORE_INSERT_CHECKS = FALSE;
2. If you want disable all After Insert triggers.
SET @TRIGGER_AFTER_INSERT_CHECKS = FALSE;
3. If you want disable all Before Update triggers.
SET @TRIGGER_BEFORE_UPDATE_CHECKS = FALSE;
4. If you want disable all After Update triggers.
SET @TRIGGER_AFTER_UPDATE_CHECKS = FALSE;
5. If you want disable all Before Delete triggers.
 SET @TRIGGER_BEFORE_DELETE_CHECKS = FALSE;
6. If you want disable all After Delete triggers.
 SET @TRIGGER_AFTER_DELETE_CHECKS = FALSE;
7. If you want disable all triggers.
SET @TRIGGER_CHECKS = FALSE;

If you want enable triggers just pass "TRUE" in query.


Cheers!!!