MySQL Server Logs
日志记录存储方式
#日志记录存储方式
mysql> show variables like 'log_output';
mysql> set global log_output='FILE,TABLE';
1、错误日志
#、错误日志
mysql> show variables like 'log_error';
+---------------+----------------------------------+
| Variable_name | Value |
+---------------+----------------------------------+
| log_error | /usr/local/mysql/data/VMUest.err |
+---------------+----------------------------------+
2、普通查询日志
#、普通查询日志
mysql> show variables like 'general_log%';
+------------------+----------------------------------+
| Variable_name | Value |
+------------------+----------------------------------+
| general_log | OFF |
| general_log_file | /usr/local/mysql/data/VMUest.log |
+------------------+----------------------------------+
#设置普通日志路径并开启(临时,重启后失效)
mysql> set global general_log_file='/usr/local/mysql/data/mysql-general.log';
mysql> set global general_log =;
#测试语句
mysql> show databases;
mysql> use sakila;
mysql> select * from actor limit ;
#查看普通日志
[root@VMUest data]# more /usr/local/mysql/data/mysql-general.log
/usr/local/mysql/bin/mysqld, Version: 5.6. (Source distribution). started with:
Tcp port: Unix socket: /usr/local/mysql/mysql.sock
Time Id Command Argument
:: Query show databases
:: Query use sakila
:: Query select * from actor limit
3、慢查询日志
#、慢查询日志
mysql> show variables like 'slow_query_log%';
+---------------------+---------------------------------------+
| Variable_name | Value |
+---------------------+---------------------------------------+
| slow_query_log | OFF |
| slow_query_log_file | /usr/local/mysql/data/VMUest-slow.log |
+---------------------+---------------------------------------+
#设置慢查询日志路径并开启(临时,重启后失效)
mysql> set global slow_query_log_file='/usr/local/mysql/data/mysql-slow.log';
mysql> set global slow_query_log=;
#运行时间>long_query_time的记录到日志
mysql> show global variables like 'long_query_time';
mysql> set global long_query_time=;
#测试语句(需在新窗口执行)
mysql> select sleep(); # 未使用索引的查询也被记录到慢查询日志中
mysql> show variables like 'log_queries_not_using_indexes';
mysql> set global log_queries_not_using_indexes=;
#测试语句
mysql> select * from actor;
mysql> explain select * from actor;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | actor | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
#查看慢查询日志
[root@VMUest data]# more /usr/local/mysql/data/mysql-slow.log
/usr/local/mysql/bin/mysqld, Version: 5.6. (Source distribution). started with:
Tcp port: Unix socket: /usr/local/mysql/mysql.sock
Time Id Command Argument
# Time: ::
# User@Host: mydba[mydba] @ [192.168.85.1] Id:
# Query_time: 3.014669 Lock_time: 0.000000 Rows_sent: Rows_examined:
use test;
SET timestamp=;
select sleep();
# Time: ::
# User@Host: mydba[mydba] @ [192.168.85.1] Id:
# Query_time: 0.003183 Lock_time: 0.000320 Rows_sent: Rows_examined:
use sakila;
SET timestamp=;
select * from actor; #mysqldumpslow分析慢查询日志(配置好环境变量)
[root@VMUest data]# mysqldumpslow -s c -t /usr/local/mysql/data/mysql-slow.log
Reading mysql slow query log from /usr/local/mysql/data/mysql-slow.log
Count: Time=.00s (0s) Lock=.00s (0s) Rows=4.0 (), mydba[mydba]@[192.168.85.1]
select * from actor limit N
Count: Time=.00s (0s) Lock=.00s (0s) Rows=200.0 (), mydba[mydba]@[192.168.85.1]
select * from actor
Count: Time=.00s (3s) Lock=.00s (0s) Rows=1.0 (), mydba[mydba]@[192.168.85.1]
select sleep(N) # 多少条慢查询记录,可以使用系统变量
mysql> show global status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries | |
+---------------+-------+
日志文件备份
mysql> flush logs; 等效于 shell>mysqladmin flush-logs
flush logs可以添加具体的日志类型:flush error logs、flush general logs、flush binary logs、flush slow logs
A log-flushing operation does the following:
If general query logging or slow query logging to a log file is enabled, the server closes and reopens the general query log file or slow query log file.
If binary logging is enabled, the server closes the current binary log file and opens a new log file with the next sequence number.
If the server was started with the --log-error [406] option to cause the error log to be written to a file, the server closes and reopens the log file.
The server creates a new binary log file when you flush the logs. However, it just closes and reopens the general and slow query log files. To cause new files to be created on Unix, rename the current log files before flushing them. At flush time, the server opens new log files with the original names.
因此对于二进制日志之外的日志文件,通常是重命名当前的日志文件,然后flush-log来创建新日志文件
[root@VMUest ~]# cd /usr/local/mysql/data
[root@VMUest data]# mv mysql-general.log mysql-general.log.old
[root@VMUest data]# mv mysql-slow.log mysql-slow.log.old
mysql> flush general logs;
#执行mv命令后,日志记录到.old文件;执行flush命令后(flush命令记录在old文件),创建"新"文件用于记录之后的记录
MySQL Server Logs的更多相关文章
- MySQL Server类型之MySQL客户端工具的下载、安装和使用
本博文的主要内容有 .MySQL Server 5.5系列的下载 .MySQL Server 5.5系列的安装 .MySQL Server 5.5系列的使用 .MySQL Server 5.5系列的卸 ...
- MySQL Server类型之MySQL客户端工具的下载、安装和使用(博主推荐)
本博文的主要内容有 .MySQL Server 5.5系列的下载 .MySQL Server 5.5系列的安装 .MySQL Server 5.5系列的使用 .MySQL Server 5.5系列的卸 ...
- percona innobackupex 遇到 connect to MySQL server as DBD::mysql module is not installed 问题
percona innobackupex connect to MySQL server as DBD::mysql module is not installed [root@mysql softw ...
- 【Problem】xampp in ubuntu下命令行启动mysql报错: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)
xampp in ubuntu下命令行启动mysql报错: reddevil@reddevil-Lenovo:/opt/lampp$ ./bin/mysql -u root -p Enter pass ...
- 2003-Can't connect to mysql server on localhost (10061)
mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法
远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...
- mySql 远程连接(is not allowed to connect to this MySQL server)
如果你想连接你的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL serve ...
- 报错:1130-host ... is not allowed to connect to this MySql server
报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在l ...
- 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
mysql,mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误: ERROR 2002 (HY000): Can't connect to local MySQL se ...
随机推荐
- Git的配置及克隆项目到本地
- [CF1244C] The Football Season【数学,思维题,枚举】
Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\), ...
- css---6伪元素选择器
after :在内容后边 <!DOCTYPE html> <html lang="en"> <head> & ...
- CodeForces - 803F
http://codeforces.com/problemset/problem/803/F #include <iostream> #include <cstdio> #in ...
- mysql 查询当前日期
1.本年份 SELECT DATE_FORMAT(NOW(), '%Y'); 2.本月份(显示数字) SELECT DATE_FORMAT(NOW(), '%m'); 3.本月份(显示英文) SELE ...
- Kubernetes的包管理工具Helm的安装和使用
1.源码安装 [root@master ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64 ...
- sass与less的区别?Stylus又是啥?
现在写样式大家基本上都会用上CSS预处理器,而比较流行的预处理器就是这三位老哥了Less.Sass 和 Stylus: 在这之前,我们先了解一点,sass和scss有什么区别? SCSS 是 Sass ...
- Java-Maven-pom.xml-porject-parent:parent
ylbtech-Java-Maven-pom.xml-porject-parent:parent 1.返回顶部 1.Inherit defaults from Spring Boot <!-- ...
- 引用第三方 chalk 模块
第三方模块没有默认引用到我们的电脑中,我们要进行下载 chalk 这个包是为了使输出不再单调,添加文字背景什么的,改变字体颜色什么的, npm install chalk //只需要写文件包名,不需要 ...
- C语言进阶学习第二章
本章重点记录指针的各种概念: 1.地址与内容 2.非法的赋值 3.NULL指针:NULL指针作为一个特殊的指针变量,表示不指向任何东西,在对指针进行解引用操作之前,首先必须 确保它并非NULL指针. ...