doc/笔记/开启Mysql数据库日志-open-mysql-log.md

56 lines
873 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 开启Mysql数据库日志
date: 2023-04-19 15:43:58.709
updated: 2023-04-19 17:20:44.772
url: /archives/open-mysql-log
categories:
- 数据库
tags:
- DB
---
想查看数据库执行SQL的记录可以开启日志默认是OFF状态开启后长时间输出日志会占用存储空间不需要时记得要关闭日志
## 临时开启log
**在Mysql中执行**
查看是否已经开启,并且会输出日志默认存放路径
```sql
SHOW VARIABLES LIKE "general_log%";
```
开启实时日志输出
```sql
SET GLOBAL general_log = 'ON';
```
通过tail命令实时查看Mysql日志
**这种方式在Mysql重启后会失效**
## 永久开启log
编辑my.cnf文件
```sh
vim /etc/my.cnf
```
加入下面两行
```
general_log = 1
general_log_file = /var/log/mysql/general_sql.log
```
重启mysql生效
```sh
service mysqld restart
```