日志记录存储方式

#日志记录存储方式
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的更多相关文章

  1. MySQL Server类型之MySQL客户端工具的下载、安装和使用

    本博文的主要内容有 .MySQL Server 5.5系列的下载 .MySQL Server 5.5系列的安装 .MySQL Server 5.5系列的使用 .MySQL Server 5.5系列的卸 ...

  2. MySQL Server类型之MySQL客户端工具的下载、安装和使用(博主推荐)

    本博文的主要内容有 .MySQL Server 5.5系列的下载 .MySQL Server 5.5系列的安装 .MySQL Server 5.5系列的使用 .MySQL Server 5.5系列的卸 ...

  3. 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 ...

  4. 【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 ...

  5. 2003-Can't connect to mysql server on localhost (10061)

    mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...

  6. 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 ...

  7. 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 ...

  8. 报错:1130-host ... is not allowed to connect to this MySql server

    报错:1130-host ... is not allowed to connect to this MySql server   解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在l ...

  9. 连接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 ...

随机推荐

  1. JAVA-基础(Stream流)

    说起stream流大家的第一反应是io,但是实际上谁规定流一定是存在io包里呢?在java8中得益于Lambda表达式的函数式编程,引入了一个全新的概念,stream. 1.优势? 在java8之前我 ...

  2. 2019-6-23-WPF-解决弹出模态窗口关闭后,主窗口不在最前

    title author date CreateTime categories WPF 解决弹出模态窗口关闭后,主窗口不在最前 lindexi 2019-06-23 11:48:38 +0800 20 ...

  3. Win32SDK应用程序

    转自:https://blog.csdn.net/jxf_ioriyagami/article/details/1486626 1 说在前面    由于VC6及MFC的特点,我们许多人从标准C++学习 ...

  4. 2019牛客暑期多校训练营(第八场)I-Inner World DFS序+主席树(扫描线也可)

    题目传送门 题意:初始有n棵树,每棵树都只有1个n号节点,现在有m次添加操作,每次操作是将$[l,r]$范围内的树的$u$节点后面添加一个$v$节点.每个v节点只会被添加一次. 然后是q次询问,输出$ ...

  5. js代码触发事件

    /*** * 需要触发谁的点击事件 * @param how_id 节点的id 如:<input id='test'/> 则how_id=test * @param how_this 这个 ...

  6. BZOJ 1037 (ZJOI 2008) 生日聚会

    题目描述 今天是hidadz小朋友的生日,她邀请了许多朋友来参加她的生日party. hidadz带着朋友们来到花园中,打算坐成一排玩游戏.为了游戏不至于无聊,就座的方案应满足如下条件: 对于任意连续 ...

  7. (转)HttpURLConnection中设置网络超时

    转:http://www.xd-tech.com.cn/blog/article.asp?id=37 Java中可以使用HttpURLConnection来请求WEB资源.HttpURLConnect ...

  8. iOS开发UIMotionEffect运动视觉效果

    1.UIMotionEffect简介 在iOS7.0推出了UIMotionEffect运动视觉效果,就是从屏幕偏移不同角度.看到的效果不同! NS_CLASS_AVAILABLE_IOS(7_0) @ ...

  9. Android Drawable 详解(教你画画!)

    参考 1.Android中的Drawable基础与自定义Drawable 2.android中的drawable资源 3.Android开发之Shape详细解读 Drawable分类 No xml标签 ...

  10. codeforces 1100D-Dasha and Chess

    传送门:QAQQAQ 题意:This is an interactive task. 999*999国际象棋棋盘中有一个王和666个车,玩家走王,电脑走车,玩家先走,玩家的目的是让对方的车将到自己的王 ...