前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >general_log 问题处理8

general_log 问题处理8

作者头像
franket
发布于 2022-03-21 10:27:03
发布于 2022-03-21 10:27:03
49300
代码可运行
举报
文章被收录于专栏:技术杂记技术杂记
运行总次数:0
代码可运行

执行正常,顺利完成升级

重启服务,查看error日志里的信息,关注有无报错

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@upgrade-slave ~]# /etc/init.d/mysql  stop 
Shutting down MySQL (Percona Server)..[  OK  ]

[root@upgrade-slave ~]# /etc/init.d/mysql  start 
Starting MySQL (Percona Server)...[  OK  ]

[root@upgrade-slave ~]#

检查无误后,配置master,启动同步就可以了


命令汇总

  • time mysql_upgrade -u root -p
  • ll ./mysql/general_log.CSV
  • ll general_log.
  • du -sh general_log.*
  • file general_log.CSV
  • cat general_log.CSV
  • touch general_log.CSV
  • chown mysql.mysql general_log.CSV
  • chmod 660 general_log.CSV

The General Query Log

The General Query Log

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
5.2.3 The General Query Log

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order is in contrast with that of the binary log, for which statements are written after they are executed but before any locks are released. In addition, the query log may contain statements that only select data while such statements are never written to the binary log.

When using statement-based binary logging on a replication master server, statements received by its slaves are written to the query log of each slave. Statements are written to the query log of the master server if a client reads events with the mysqlbinlog utility and passes them to the server.

However, when using row-based binary logging, updates are sent as row changes rather than SQL statements, and thus these statements are never written to the query log when binlog_format is ROW. A given update also might not be written to the query log when this variable is set to MIXED, depending on the statement used. See Section 17.1.2.1, “Advantages and Disadvantages of Statement-Based and Row-Based Replication”, for more information.

By default, the general query log is disabled. To specify the initial general query log state explicitly, use --general_log[={0|1}]. With no argument or an argument of 1, --general_log enables the log. With an argument of 0, this option disables the log. To specify a log file name, use --general_log_file=file_name. To specify the log destination, use --log-output (as described in Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).

If you specify no name for the general query log file, the default name is host_name.log. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

To disable or enable the general query log or change the log file name at runtime, use the global general_log and general_log_file system variables. Set general_log to 0 (or OFF) to disable the log or to 1 (or ON) to enable it. Set general_log_file to specify the name of the log file. If a log file already is open, it is closed and the new file is opened.

When the general query log is enabled, the server writes output to any destinations specified by the --log-output option or log_output system variable. If you enable the log, the server opens the log file and writes startup messages to it. However, further logging of queries to the file does not occur unless the FILE log destination is selected. If the destination is NONE, the server writes no queries even if the general log is enabled. Setting the log file name has no effect on logging if the log destination value does not contain FILE.

Server restarts and log flushing do not cause a new general query log file to be generated (although flushing closes and reopens it). To rename the file and create a new one, use the following commands:

shell> mv host_name.log host_name-old.log
shell> mysqladmin flush-logs
shell> mv host_name-old.log backup-directory

On Windows, use rename rather than mv.

You can also rename the general query log file at runtime by disabling the log:

SET GLOBAL general_log = 'OFF';

With the log disabled, rename the log file externally; for example, from the command line. Then enable the log again:

SET GLOBAL general_log = 'ON';

This method works on any platform and does not require a server restart.

The session sql_log_off variable can be set to ON or OFF to disable or enable general query logging for the current connection.

As of MySQL 5.6.3, passwords in statements written to the general query log are rewritten by the server not to occur literally in plain text. Password rewriting can be suppressed for the general query log by starting the server with the --log-raw option. This option may be useful for diagnostic purposes, to see the exact text of statements as received by the server, but for security reasons is not recommended for production use.

Before MySQL 5.6.3, passwords in statements are not rewritten and the general query log should be protected. See Section 6.1.2.3, “Passwords and Logging”.

One implication of the introduction of password rewriting in MySQL 5.6.3 is that statements that cannot be parsed (due, for example, to syntax errors) are no longer written to the general query log because they cannot be known to be password free. Use cases that require logging of all statements including those with errors should use the --log-raw option, bearing in mind that this also bypasses password writing.

log-output

Command-Line Format

--log-output=name

System Variable

Name

log_output

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

set

Default

FILE

Valid Values

TABLE

FILE

NONE

Selecting General Query and Slow Query Log Output Destinations

Selecting General Query and Slow Query Log Output Destinations

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
5.2.1 Selecting General Query and Slow Query Log Output Destinations

MySQL Server provides flexible control over the destination of output to the general query log and the slow query log, if those logs are enabled. Possible destinations for log entries are log files or the general_log and slow_log tables in the mysql database. Either or both destinations can be selected.

Before MySQL 5.5.7, logging to tables incurs significantly more server overhead than logging to files. If you enable the general log or slow query log and require highest performance, you should use file logging, not table logging.

Log control at server startup. The --log-output option specifies the destination for log output. This option does not in itself enable the logs. Its syntax is --log-output[=value,...]:

If --log-output is given with a value, the value should be a comma-separated list of one or more of the words TABLE (log to tables), FILE (log to files), or NONE (do not log to tables or files). NONE, if present, takes precedence over any other specifiers.

If --log-output is omitted, the default logging destination is FILE.

The general_log system variable controls logging to the general query log for the selected log destinations. If specified at server startup, general_log takes an optional argument of 1 or 0 to enable or disable the log. To specify a file name other than the default for file logging, set the general_log_file variable. Similarly, the slow_query_log variable controls logging to the slow query log for the selected destinations and setting slow_query_log_file specifies a file name for file logging. If either log is enabled, the server opens the corresponding log file and writes startup messages to it. However, further logging of queries to the file does not occur unless the FILE log destination is selected.

Examples:

To write general query log entries to the log table and the log file, use --log-output=TABLE,FILE to select both log destinations and --general_log to enable the general query log.

To write general and slow query log entries only to the log tables, use --log-output=TABLE to select tables as the log destination and --general_log and --slow_query_log to enable both logs.

To write slow query log entries only to the log file, use --log-output=FILE to select files as the log destination and --slow_query_log to enable the slow query log. (In this case, because the default log destination is FILE, you could omit the --log-output option.)

Log control at runtime. The system variables associated with log tables and files enable runtime control over logging:

The global log_output system variable indicates the current logging destination. It can be modified at runtime to change the destination.

The global general_log and slow_query_log variables indicate whether the general query log and slow query log are enabled (ON) or disabled (OFF). You can set these variables at runtime to control whether the logs are enabled.

The global general_log_file and slow_query_log_file variables indicate the names of the general query log and slow query log files. You can set these variables at server startup or at runtime to change the names of the log files.

To disable or enable general query logging for the current connection, set the session sql_log_off variable to ON or OFF.

The use of tables for log output offers the following benefits:

Log entries have a standard format. To display the current structure of the log tables, use these statements:

SHOW CREATE TABLE mysql.general_log;
SHOW CREATE TABLE mysql.slow_log;

Log contents are accessible through SQL statements. This enables the use of queries that select only those log entries that satisfy specific criteria. For example, to select log contents associated with a particular client (which can be useful for identifying problematic queries from that client), it is easier to do this using a log table than a log file.

Logs are accessible remotely through any client that can connect to the server and issue queries (if the client has the appropriate log table privileges). It is not necessary to log in to the server host and directly access the file system.

The log table implementation has the following characteristics:

In general, the primary purpose of log tables is to provide an interface for users to observe the runtime execution of the server, not to interfere with its runtime execution.

CREATE TABLE, ALTER TABLE, and DROP TABLE are valid operations on a log table. For ALTER TABLE and DROP TABLE, the log table cannot be in use and must be disabled, as described later.

By default, the log tables use the CSV storage engine that writes data in comma-separated values format. For users who have access to the .CSV files that contain log table data, the files are easy to import into other programs such as spreadsheets that can process CSV input.

The log tables can be altered to use the MyISAM storage engine. You cannot use ALTER TABLE to alter a log table that is in use. The log must be disabled first. No engines other than CSV or MyISAM are legal for the log tables.

To disable logging so that you can alter (or drop) a log table, you can use the following strategy. The example uses the general query log; the procedure for the slow query log is similar but uses the slow_log table and slow_query_log system variable.

SET @old_log_state = @@global.general_log;
SET GLOBAL general_log = 'OFF';
ALTER TABLE mysql.general_log ENGINE = MyISAM;
SET GLOBAL general_log = @old_log_state;

TRUNCATE TABLE is a valid operation on a log table. It can be used to expire log entries.

RENAME TABLE is a valid operation on a log table. You can atomically rename a log table (to perform log rotation, for example) using the following strategy:

USE mysql;
DROP TABLE IF EXISTS general_log2;
CREATE TABLE general_log2 LIKE general_log;
RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;

As of MySQL 5.5.7, CHECK TABLE is a valid operation on a log table.

LOCK TABLES cannot be used on a log table.

INSERT, DELETE, and UPDATE cannot be used on a log table. These operations are permitted only internally to the server itself.

FLUSH TABLES WITH READ LOCK and the state of the read_only system variable have no effect on log tables. The server can always write to the log tables.

Entries written to the log tables are not written to the binary log and thus are not replicated to slave servers.

To flush the log tables or log files, use FLUSH TABLES or FLUSH LOGS, respectively.

Partitioning of log tables is not permitted.

Before MySQL 5.5.25, mysqldump does not dump the general_log or slow_query_log tables for dumps of the mysql database. As of 5.5.25, the dump includes statements to recreate those tables so that they are not missing after reloading the dump file. Log table contents are not dumped.

原文地址

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
Go语言的标准输入-scan 和bufio
除了f mt 和 os ,我们还需要用到 bufio 来实现带缓冲输入(input)和输出(output)读取用户的输入数据 我们怎样读取用户从键盘(控制台)输入的数据?输入指从键盘或其它标准输入(os.Stdin)读取数据。最简单的方法是使用fmt包里的Scan-或Sscan-系列函数,下面用个例子说明一下: //read input from the console:package main import "fmt" var ( firstName, lastName, s string i
李海彬
2018/03/19
2.4K0
Golang之文件读写
读写文件,不添加文件路径,默认写入到GOPATH路径下 终端读写: 源码 func Sscanf func Sscanf(str string, format string, a ...interface{}) (n int, err error) 解释:Sscanf scans the argument string, storing successive space-separated values into successive arguments as determined by the form
超蛋lhy
2018/08/31
1.2K0
Golang之文件读写
go语言学习之读取用户输入
本学习笔记全部以代码块的形式展示,具体的内容都包含在代码里: package types import ( "bufio" "fmt" "os" "strconv" "strings" ) // 读取输入 // 1. fmt.Scanln 和 fmt.Scanf 都是扫描来自标准输入的文本 // 2. Sscan 和以 Sscan 开头的函数则是从字符串读取 // 3. 也可以使用 bufio 包提供的缓冲读取(buffered reader)来读取数据 // bufio.
张宗伟 plus
2023/01/04
6090
Go 输入输出
fmt包实现了类似C语言printf和scanf的格式化I/O。主要分为向外输出内容和获取输入内容两大部分。
看、未来
2022/06/19
3350
Golang语言(打卡第四天)fmt格式化工具|Go主题月
Print系列函数会将内容输出到系统的标准输出,区别在于Print函数直接输出内容,Printf函数支持格式化输出字符串,Println函数会在输出内容的结尾添加一个换行符。
微芒不朽
2022/09/13
8600
Go基础--终端操作和文件操作
终端操作 操作终端相关的文件句柄常量 os.Stdin:标准输入 os.Stdout:标准输出 os.Stderr:标准错误输出 关于终端操作的代码例子: package main import "fmt" var ( firstName,lastName,s string i int f float32 input = "56.12/5212/Go" format = "%f/%d/%s" ) func main() { fmt.Println("pl
coders
2018/03/30
7270
一文搞懂Go语言标准库,fmt
fmt 包含有格式化I/O函数,类似于C语言的 printf 和 scanf。主要分为向外输出内容和获取输入内容两大部分。
微客鸟窝
2021/12/21
5460
Go 常用标准库之 fmt 介绍与基本使用
fmt 是 Go 语言中的一个常用标准库,它用于格式化输入和输出数据。fmt 包提供了一系列函数,可以帮助你将数据以特定的格式打印到标准输出(通常是终端)或将数据格式化为字符串以供后续处理。这个库的名称 "fmt" 来自于 "format",因为它主要用于格式化数据。
贾维斯Echo
2023/10/26
5260
第16节 键盘输入和打印输出
fmt包实现了类似C语言printf和scanf的格式化I/O。格式化verb('verb')源自C语言但更简单。
小尘哥
2019/07/12
6300
第16节 键盘输入和打印输出
使用GO语言灵活批量ssh登录服务器执行操作
在工作中时常需要登录服务器做一系列操作,每次输入ssh xxx总是很麻烦。这时候为什么不考虑写一个通用的小脚本呢?
zhangheng
2020/04/28
1.8K0
golang fmt(格式换 I O接口)
fmt 方法可以大致分为 print, scan两类, 根据基础方法可以构建特定方法。
copy_left
2019/08/21
9820
100天精通Golang(基础入门篇)——第7天:深入学习键盘输入和打印输出,掌握常用函数和包
在编程过程中,键盘输入和打印输出是基础而重要的操作。本文将介绍如何使用Go语言的fmt包进行打印输出,以及如何从键盘获取输入。通过学习这些知识,你将能够更加灵活地处理用户输入和输出信息,提升程序的交互性和可读性。
猫头虎
2024/04/08
1860
100天精通Golang(基础入门篇)——第7天:深入学习键盘输入和打印输出,掌握常用函数和包
《Go小技巧&易错点100例》第二十七篇
在Go语言中,Scan函数是一个强大的工具,它主要用于从输入源(如标准输入、文件或网络连接)读取数据,并将其解析为指定的变量类型。
闫同学
2025/01/17
990
手把手教你用go语言实现聊天室
手撕代码八百里
2024/01/10
3980
Go语言实现TCP服务端和客户端
TCP/IP(Transmission Control Protocol/Internet Protocol) 即传输控制协议/网间协议,是一种面向连接(连接导向)的、可靠的、基于字节流的传输层(Transport layer)通信协议,因为是面向连接的协议,数据像水流一样传输,会存在黏包问题。
ccf19881030
2020/10/28
10.6K0
Go语言实现TCP服务端和客户端
(三十六)golang--文件的基本操作
2.读取文件中的内容,并显示给终端(带缓冲区的方式),使用os.Open(),file.Close(),bufio.NewReader(),reader.ReadString()
西西嘛呦
2020/08/26
3050
Golang文件操作-上篇
1、读文件 2、写文件 3、文件指针 4、ioutil文件操作 4.1 readall读取文件所有内容 4.2 readfile直接读文件 4.3 writefile直接写文件 5、bufio带缓冲IO 5.1 scanner 逐行读取 5.2 带缓冲IO reader 5.2.1 read 读 5.2.2 readline 读 5.2.3 readstring、readslice 读 5.3 带缓冲IO writer 1、读文件 读文件的过程 文件位置 打开文件 读取文件内容(逐个字符读、按
仙人技术
2021/09/23
6440
Golang文件操作-上篇
golang bufio包怎么用?
上面实现了一个简单的文件读取功能,能正常工作,但是有一个有一个问题,每次从文件读取3个字节,而且读取了10次,也就是读取了3 * 10 = 30个字节的数据,却做了10次io操作,性能可想而知。
每周聚焦
2024/06/17
1980
golang bufio包怎么用?
golang bufio 缓冲io
该缓冲区是 Reader Writer 接口集合对象 { *Reader, *Writer }
copy_left
2019/08/23
1.5K0
Golang读写文件操作
最近在使用Golang进行文件读写的过程中,遇到几个细节问题导致程序写入数据时有一定脏数据的残留,最后发现是使用os.OpenFile在进行文件操作的时候没有使用正确的flag造成的。因此专门去学习了下Golang中读写文件的几种方式方法,在此记录下一些简单的操作,防止以后遗忘。 读文件 使用golang语言去读取一个文件默认会有多种方式,这里主要介绍以下几种。 使用ioutil直接读取 需要引入io/ioutil包,该包默认拥有以下函数供用户调用。 func NopCloser(r io.Reader)
BGBiao
2018/02/26
4.2K0
相关推荐
Go语言的标准输入-scan 和bufio
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文