1. Logging queries in mysql

    A nice simple way to log all the queries being run…

    From the mysql command line type these.

    1) execute “SET GLOBAL log_output = ‘TABLE’;”
    2) execute “SET GLOBAL general_log = ‘ON’;”
    3) take a look at the table mysql.general_log 

    It’s basically telling mysql to log all it’s queries to a system table, easy!

  2. The best way of IP address in Mysql

    After needing this for something at work I found this entry on a mysql list.

    http://lists.mysql.com/cluster/2784

    The best parts of which are that it’s best to store a INT(10) value - so you have to turn the IP in to an integer.

    Luckily Mysql has 2 functions to do this for you..

    INET_ATON() and INET_NTOA()

    For example.. 

    mysql> SELECT INET_ATON(‘192.168.0.2’);

    +—————————————+
    |         INET_ATON(‘192.168.0.2’) |
    +—————————————+
    |                             3232235522 |
    +—————————————+

    OR

    mysql> SELECT INET_NTOA(‘3232235522’);

    +————————————-+
    | INET_NTOA(‘3232235522’) |
    +————————————-+
    | 192.168.0.2             |
    +————————————-+

    Simple and easy!