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 ...
随机推荐
- LeetCode动态规划题总结【持续更新】
以下题号均为LeetCode题号,便于查看原题. 10. Regular Expression Matching 题意:实现字符串的正则匹配,包含'.' 和 '*'.'.' 匹配任意一个字符,&quo ...
- leetcode-8-字符串转换整数(atoi)
题目描述: 方法一:正则 class Solution: def myAtoi(self, str: str) -> int: return max(min(int(*re.findall('^ ...
- js结巴程序
var str="我.....我是一个个......帅帅帅帅哥!"; var reg=/\./gi; str=str.replace(reg,""); reg= ...
- Linux g++
Usage: g++ [options] file...Options: -pass-exit-codes Exit with highest error code from a p ...
- thinkphp empty标签
empty标签用于判断某个变量是否为空,用法: 大理石平台检验标准 <empty name="name"> name为空值 </empty> 如果判断没有赋 ...
- 跨域问题The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by t
withCredentials 属性 上面说到,CORS请求默认不发送Cookie和HTTP认证信息.如果要把Cookie发到服务器,一方面要服务器同意,指定Access-Control-Allow- ...
- from urllib import parse模块的使用
一.介绍 定义了url的标准接口,实现url的各种抽取 parse模块的作用:url的解析,合并,编码,解码 二.代码 方法一:urlparse 实现url的识别和分段 from urllib imp ...
- WordPress 3.8 中文正式版下载 - 建站与学习首选!全球最流行的开源PHP博客网站程序
转载自:http://www.iplaysoft.com/wordpress.html 话说虽然我一直都在网站底部写着本站基于 WordPress 构建,但时常还是有人问我网站是用什么程序建的,还真有 ...
- id(), is, ==, 的区别与小数据池
1. id() 内存地址 s = 'asdf' n = id(s) print(n)输出:16506464 #16506464为变量s的内存地址 2. == 比较数值 3. is 比较内存地址 数字, ...
- 第四篇:java读取Excel简单模板
场景:对于经常需要导入Excel模板或数据来解析后加以应用的,使用频率非常之高,做了一个比较稳定的版本,体现在这些地方工具:org.apache.poi使用前必须了解这些:1.要解析,那肯定先判断是不 ...