当前位置:网站首页>MySQL log query log
MySQL log query log
2022-07-27 20:37:00 【Hua Weiyun】
28.1 Query log
MySQL The query log in is saved in a text file , Be able to record MySQL All data operations in . This section briefly introduces how to open 、 View and delete MySQL Query log in .
28.1.1 Open query log
MySQL Query logs are not enabled by default , If you need to open the query log , You need to in my.cnf Documents or my.ini Of documents [mysqld] Select to configure . for example , Configuration on MySQL Query log :
[mysqld]general_log = 1general_log_file = /data/mysql/log/general_log/general_statement.loglog_output = FILEVarious configurations are described below :
·general_log: Indicates whether the query log is enabled . This is set to 1 Or without any value , You can open the query log ; Set to 0 Or in my.cnf File or my.ini This item is not configured in the file , The query log will not be opened .
·general_log_file: Query the file directory of the log , The full path of the log is configured here .
·log_output: Indicates how logs are stored , There can be 3 Species value ,TABLE Indicates that the query log is stored in the data table ;FILE Means to save the query log to a file ;NONE It means that the log information is not saved to the data table and file .
Be careful : When opening the query log , If not specified general_log_file Options and log_output The value of the option , be MySQL The query log will be saved to DATADIR Under the directory specified by the option ( That is, the data directory in the database ), The default file name is host_name.log, among ,host_name by MySQL The host name .
Configure before starting the query log , First of all to see /data/mysql/log/general_log File information in directory .
[[email protected] ~]# [[email protected] ~]# ll /data/mysql/log/general_log/total 0When not configured MySQL When querying logs for ,/data/mysql/log/general_log/ There are no files in the directory .
After the query log configuration is completed , Need to restart MySQL Service to take effect .
[[email protected] ~]# service mysqld restartShutting down MySQL..... SUCCESS! Starting MySQL........ SUCCESS!It can also be in MySQL Specify on the command line MySQL Query log .
mysql> SET GLOBAL general_log = 1;Query OK, 0 rows affected (0.01 sec)mysql> SET GLOBAL general_log_file = '/data/mysql/log/general_log/general_statement.log'; Query OK, 0 rows affected (0.00 sec)mysql> SET GLOBAL log_output = 'file';Query OK, 0 rows affected (0.00 sec)here , Look again /data/mysql/log/general_log/ A file in a directory .
[[email protected] ~]# ll /data/mysql/log/general_log/total 4-rw-r----- 1 mysql mysql 547 Jan 17 11:39 general_statement.logWhen the query log configuration is completed ,MySQL Automatically created general_log_file Option to specify the log file .
28.1.2 View query log
If log_output The option is configured to save the query log to a file , Then the format of the log file is plain text , You can directly view the contents of the log file .
for example , towards goods Database based t_goods_category Insert a piece of data into the data table , Then the query t_goods_category Data in the data table , And check the contents in the query log .
(1) Insert data into a data table .
mysql> USE goods;Database changedmysql> INSERT INTO t_goods_category -> (id, t_category) -> VALUES -> (6, ' food ');Query OK, 1 row affected (0.01 sec)(2) Data table view .
mysql> SELECT * FROM t_goods_category;+----+---------------------+| id | t_category |+----+---------------------+| 1 | Women's wear / Women's Boutique || 2 | Outdoor sports || 3 | men's wear || 4 | Children's wear || 5 | motion || 6 | food |+----+---------------------+6 rows in set (0.01 sec)(3) View the contents in the query log .
[[email protected] ~]# cat /data/mysql/log/general_log/general_statement.log/usr/local/mysql/bin/mysqld, Version: 8.0.18 (binghe edition). started with:Tcp port: 3306 Unix socket: /data/mysql/run/mysql.sockTime Id Command Argument2020-01-17T03:39:34.706121Z 8 Query SET GLOBAL general_log_file = '/data/mysql/log/general_log/general_statement.log'/usr/local/mysql/bin/mysqld, Version: 8.0.18 (binghe edition). started with:Tcp port: 3306 Unix socket: /data/mysql/run/mysql.sockTime Id Command Argument2020-01-17T03:39:49.435725Z 8 Query SET GLOBAL log_output = 'file'2020-01-17T03:53:06.278557Z 8 Query SELECT DATABASE()2020-01-17T03:53:06.278867Z 8 Init DB goods2020-01-17T03:53:49.479114Z 8 Query INSERT INTO t_goods_category(id, t_category)VALUES(6, ' food ')2020-01-17T03:54:04.014541Z 8 Query SELECT * FROM t_goods_categoryThe query log records all SQL Statement information .
28.1.3 Delete the query log
The query log is saved on the server disk in the form of a plain text file . You can delete the query log directly . If you need to re-establish the query log , You need to in MySQL Execute... On the command line FLUSH LOGS Command or execute in the server command line mysqladmin flush-logs command .
(1) Delete the query log .
rm -rf /data/mysql/log/general_log/general_statement.loghere , see /data/mysql/log/general_log A file in a directory .
[[email protected] ~]# ll /data/mysql/log/general_logtotal 0Results show , The query log file has been deleted .
(2) Refresh the query log .
Can be in MySQL Execute the following command on the command line to refresh the log .
mysql> FLUSH LOGS;Query OK, 0 rows affected (0.02 sec)You can also execute the following command in the server command line to refresh the log .
[[email protected] ~]# mysqladmin -uroot -p flush-logsEnter password:Log refresh succeeded , Look again /data/mysql/log/general_log A file in a directory .
[[email protected] ~]# ll /data/mysql/log/general_log total 4-rw-r----- 1 mysql mysql 519 Jan 17 12:33 general_statement.logYou can see , The query log file has been recreated .
28.1.4 Close query log
It's easier to turn off the query log , Only need my.cnf Documents or my.ini Of documents [mysqld] Under Options , take general_log The options are configured to 0, Or delete general_log Options .
[mysqld]general_log = 0When the configuration is complete , restart MySQL To take effect .
It can also be in MySQL Execute the following command on the command line to close the query log .
mysql> SET GLOBAL general_log = 0;Query OK, 0 rows affected (0.00 sec)Delete the query log after closing the query log , Then refresh the log ,MySQL The query log file will not be recreated .
边栏推荐
- Koin simple to use
- Redis basic understanding, five basic data types
- 一看就懂的ESLint
- Following Huawei and MediaTek, the mobile phone chip manufacturer announced a donation of 7million yuan to Wuhan
- A recently summarized universal violent cracking method
- 速卖通:按关键字搜索商品 API
- [map set]
- 什么是多层感知机(什么是多层感知机)
- 'vite' is not an internal or external command, nor is it a runnable program or batch file
- To share the denoising methods and skills of redshift renderer, you must have a look
猜你喜欢

Ten year test old bird talk about mobile terminal compatibility test

Simple application of multipoint bidirectional republication and routing strategy

C language -- array

Two years after its release, the price increased by $100, and the reverse growth of meta Quest 2

Add joint control to gltf model

Redis queue、rdb学习

antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key

Injection attack

EasyCVR平台关闭录像为何还会有TS切片文件生成?

Redis basic understanding, five basic data types
随机推荐
同源与跨域
Common ways to keep requests idempotent
JS array method foreach and map comparison
《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24
Huawei's mobile phone shipments exceed Apple's, ranking second in the world, but it faces a large amount of inventory that needs to be cleaned up
Mongodb learning notes: bson structure analysis
传英特尔将停掉台积电16nm代工的Nervana芯片
Huawei's 150 member team rushed to the rescue, and Wuhan "Xiaotangshan" 5g base station was quickly opened!
How to run kevinchappell / FormBuilder
[rctf2015]easysql-1 | SQL injection
【深度学习】视频分类技术整理
In 2019, the global semiconductor market revenue was $418.3 billion, a year-on-year decrease of 11.9%
Unity fairygui play video (Lua)
Solve the problem of displaying the scroll bar when there is no data in the viewui table
获得微店商品详情 API
MongoDB 学习笔记: BSON 结构分析
Datepicker date selector in viewui compatible solution in ie11 browser
什么是多层感知机(什么是多层感知机)
Redis basic understanding, five basic data types
Clickhouse 实现 MaterializedPostgreSQL