Sunday, September 22, 2013

What's the difference between MyISAM and InnoDB?

MYISAM:
  1. MYISAM supports Table-level Locking
  2. MyISAM designed for need of speed
  3. MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
  4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
  5. MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.
  6. MYISAM supports fulltext search
  7. You can use MyISAM, if the table is more static with lots of select and less update and delete.
INNODB:
  1. InnoDB supports Row-level Locking
  2. InnoDB designed for maximum performance when processing high volume of data
  3. InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
  4. InnoDB stores its tables and indexes in a tablespace
  5. InnoDB supports transaction. You can commit and rollback with InnoDB

Sunday, August 11, 2013

Mysql permission to single table

If the user account already exists: 
GRANT SELECT,INSERT,UPDATE,DELETE ON database_name.table_name TO 'username'@'localhost';

 If the user account hasn't been created yet you can set it up at the same time as its permissions:

GRANT SELECT,INSERT,UPDATE,DELETE ON database_name.table_name TO 'username'@'localhost' IDENTIFIED BY 'password';

Mysql permission to single table

If the user account already exists:
GRANT SELECT,INSERT,UPDATE,DELETE ON database_name.table_name TO 'username'@'localhost';

If the user account hasn't been created yet you can set it up at the same time as its permissions:

GRANT SELECT,INSERT,UPDATE,DELETE ON database_name.table_name TO 'username'@'localhost' IDENTIFIED BY 'password';







 

Wednesday, July 24, 2013

Sunday, July 7, 2013

Mysql get last working day (satursday) of previous month

SET @dt = '2012-07-01'; -- Last day of the previous month (June 2012) was a Saturday

 SELECT CASE DAYOFWEEK(LAST_DAY(@dt-INTERVAL 1 MONTH)) 
        WHEN 1 THEN LAST_DAY(@dt-INTERVAL 1 MONTH)-INTERVAL 2 DAY 
        WHEN 7 THEN LAST_DAY(@dt-INTERVAL 1 MONTH)-INTERVAL 1 DAY 
        ELSE LAST_DAY(@dt-INTERVAL 1 MONTH)
        END x;

MYSQL get last working day(friday) of previous month

select LAST_DAY('2013-12-09' - INTERVAL 1 MONTH) -
INTERVAL (CASE WEEKDAY(LAST_DAY('2013-12-09' - INTERVAL 1 MONTH))
          WHEN 5 THEN 1
          WHEN 6 THEN 2
          ELSE 0 END) DAY

Saturday, July 6, 2013

Mysql find last friday last month---GOOD.

SET @GETLASTM=LAST_DAY('2013-08-01' - INTERVAL 1 MONTH);
SELECT DATE_FORMAT(LAST_DAY(@GETLASTM) - ((7 + WEEKDAY(LAST_DAY(@GETLASTM)) - 4) % 7), '%Y-%m-%d') last_friday;