Thursday, June 21, 2012

MYSQL log all sqls


[root@b5xox2 ~]# mysql -uroot -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.23-ndb-6.2.15-cluster-gpl MySQL Cluster Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like 'general_log%';
+------------------+---------------------------+
| Variable_name    | Value                     |
+------------------+---------------------------+
| general_log      | OFF                       |
| general_log_file | /var/lib/mysql/b5xox2.log |
+------------------+---------------------------+
2 rows in set (0.00 sec)

mysql> set global general_log = 'ON';
Query OK, 0 rows affected (0.25 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bundle             |
| mysql              |
+--------------------+
3 rows in set (0.16 sec)

mysql> use bundle
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables
    -> ;
+------------------+
| Tables_in_bundle |
+------------------+
| bundle_test      |
+------------------+
1 row in set (0.01 sec)

mysql> select * from bundle_test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
|    5 |
+------+
5 rows in set (0.00 sec)

mysql> set global general_log = 'OFF';
Query OK, 0 rows affected (0.06 sec)

mysql>


[root@b5xox2 mysql-cluster]# tail -f /var/lib/mysql/b5xox2.log
/usr/sbin/mysqld, Version: 5.1.23-ndb-6.2.15-cluster-gpl (MySQL Cluster Server (GPL)). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
/usr/sbin/mysqld, Version: 5.1.23-ndb-6.2.15-cluster-gpl (MySQL Cluster Server (GPL)). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
120621 19:40:59    2 Query      show databases
120621 19:41:16    2 Query      SELECT DATABASE()
                    2 Init DB   bundle
                    2 Query     show databases
                    2 Query     show tables
                    2 Field List        bundle_test
120621 19:41:22    2 Query      show tables
120621 19:41:29    2 Query      select * from bundle_test
120621 19:41:41    2 Query      set global general_log = 'OFF'