----使用log_slow_queries参数打开慢查询,由于该参数已经过时,因此在err日志中将出现提示信息----修改my.cnf文件,添加log_slow_queries参数[root@node4 ~]# vi /opt/mysql5.5/my.cnf[root@node4 ~]# cat /opt/mysql5.5/my.cnf |grep '^log_slow'log_slow_queries = /tmp/mysqlslow.log----清空err日志内容:[root@node4 ~]# cat /dev/null > /tmp/mysql3306.err
[root@node4 ~]# service mysql start
Starting MySQL.... [ OK ]----查看err日志的信息[root@node4 data]# tail -f /tmp/mysql3306.err
130801 02:26:28 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5.5/data130801 2:26:28 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.130801 2:26:28 [Warning] You need to use --log-bin to make --binlog-format work.130801 2:26:28 InnoDB: The InnoDB memory heap is disabled130801 2:26:28 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
130801 2:26:28 InnoDB: Compressed tables use zlib 1.2.3
130801 2:26:28 InnoDB: Initializing buffer pool, size = 128.0M
130801 2:26:28 InnoDB: Completed initialization of buffer pool
130801 2:26:28 InnoDB: highest supported file format is Barracuda.
130801 2:26:28 InnoDB: Waiting for the background threads to start
130801 2:26:30 InnoDB: 1.1.8 started; log sequence number 3069452
130801 2:26:30 [Note] Event Scheduler: Loaded 0 events
130801 2:26:30 [Note] /opt/mysql5.5/bin/mysqld: ready for connections.
Version: '5.5.22-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution----使用slow_query_log和slow_query_log_file[root@node4 ~]# vi /opt/mysql5.5/my.cnf
[root@node4 ~]# cat /opt/mysql5.5/my.cnf |grep '^slow_query'slow_query_log = 1
slow_query_log_file = /tmp/mysqlslow.log1
[root@node4 ~]# service mysql start
Starting MySQL... [ OK ]
[root@node4 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%slow%';
+---------------------+---------------------+
| Variable_name | Value |
+---------------------+---------------------+
| log_slow_queries | ON |
| slow_launch_time | 10 |
| slow_query_log | ON |
| slow_query_log_file | /tmp/mysqlslow.log1 |
+---------------------+---------------------+
4 rows in set (0.00 sec)----关于slow_launch_time参数,首先修改一下参数值mysql> set global long_query_time=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%long_query%';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
1 row in set (0.00 sec)----进行一下相关操作,查看/tmp/mysqlslow.log1的内容mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table t as select * from information_schema.tables;
Query OK, 85 rows affected (0.38 sec)
Records: 85 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 85 rows affected (0.05 sec)
Records: 85 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 170 rows affected (0.03 sec)
Records: 170 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 340 rows affected (0.05 sec)
Records: 340 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 680 rows affected (0.08 sec)
Records: 680 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 1360 rows affected (0.29 sec)
Records: 1360 Duplicates: 0 Warnings: 0
mysql> insert into t select * from t;
Query OK, 2720 rows affected (1.49 sec)
Records: 2720 Duplicates: 0 Warnings: 0----在这里已经超过1s了,查看/tmp/mysqlslow.log1[root@node4 data]# tail -f /tmp/mysqlslow.log1
# Time: 130801 2:36:25
# User@Host: root[root] @ localhost []
# Query_time: 2.274219 Lock_time: 0.000322 Rows_sent: 0 Rows_examined: 5440
use test;
SET timestamp=1375295785;
insert into t select * from t;----log_queries_not_using_indexes参数实验mysql> show variables like '%indexes%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF |
+-------------------------------+-------+
1 row in set (0.00 sec)
mysql> set log_queries_not_using_indexes = 1;
ERROR 1229 (HY000): Variable 'log_queries_not_using_indexes' is a GLOBAL variable and should be set with SET GLOBAL
mysql> set global log_queries_not_using_indexes = 1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%indexes%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | ON |
+-------------------------------+-------+
1 row in set (0.00 sec)
mysql> desc t;
+-----------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| TABLE_CATALOG | varchar(512) | NO | | | |
| TABLE_SCHEMA | varchar(64) | NO | | | |
| TABLE_NAME | varchar(64) | NO | | | |
| TABLE_TYPE | varchar(64) | NO | | | |
| ENGINE | varchar(64) | YES | | NULL | |
| VERSION | bigint(21) unsigned | YES | | NULL | |
| ROW_FORMAT | varchar(10) | YES | | NULL | |
| TABLE_ROWS | bigint(21) unsigned | YES | | NULL | |
| AVG_ROW_LENGTH | bigint(21) unsigned | YES | | NULL | |
| DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
| MAX_DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
| INDEX_LENGTH | bigint(21) unsigned | YES | | NULL | |
| DATA_FREE | bigint(21) unsigned | YES | | NULL | |
| AUTO_INCREMENT | bigint(21) unsigned | YES | | NULL | |
| CREATE_TIME | datetime | YES | | NULL | |
| UPDATE_TIME | datetime | YES | | NULL | |
| CHECK_TIME | datetime | YES | | NULL | |
| TABLE_COLLATION | varchar(32) | YES | | NULL | |
| CHECKSUM | bigint(21) unsigned | YES | | NULL | |
| CREATE_OPTIONS | varchar(255) | YES | | NULL | |
| TABLE_COMMENT | varchar(2048) | NO | | | |
+-----------------+---------------------+------+-----+---------+-------+
21 rows in set (0.05 sec)----下面的命令是查看索引的mysql> show index from t;
Empty set (0.01 sec)
mysql> select * from t where engine='xxx';
Empty set (0.18 sec)
# Time: 130801 2:43:43
# User@Host: root[root] @ localhost []
# Query_time: 0.185773 Lock_time: 0.148868 Rows_sent: 0 Rows_examined: 5440
SET timestamp=1375296223;
select * from t where engine='xxx';
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com