RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
mysql安装日志怎么看,怎么查看mysql的运行日志

怎么查看mysql日志

mysql有好几种日志,通常日志,查询缓慢日志,错误日志,默认只有错误日志是开启的,通常日志如果开启会消耗大量系统资源,而且查看也是非常不容易。如果想看哪里出错的话,查询错误日志就可以。通常会在data文件夹下面,服务器名称.err就是日志

创新互联主要从事成都网站建设、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务长子,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

数据库的安全涉及到各方面,数据的丢失或者篡改将会带来无法估量的损失,所以数据库的安全尤为重要,我们可以通过数据库的日志来分析数据库的安全性,然会针对分析结果采取相应的措施。

如何查看mysql数据库操作记录日志?

有时候我们会不小心对一个大表进行了 update,比如说写错了 where 条件......

此时,如果 kill 掉 update 线程,那回滚 undo log 需要不少时间。如果放置不管,也不知道 update 会持续多久。

那我们能知道 update 的进度么?

实验

我们先创建一个测试数据库:

快速创建一些数据:

连续执行同样的 SQL 数次,就可以快速构造千万级别的数据:

查看一下总的行数:

我们来释放一个大的 update:

然后另起一个 session,观察 performance_schema 中的信息:

可以看到,performance_schema 会列出当前 SQL 从引擎获取的行数。

等 SQL 结束后,我们看一下 update 从引擎总共获取了多少行:

可以看到该 update 从引擎总共获取的行数是表大小的两倍,那我们可以估算:update 的进度 = (rows_examined) / (2 * 表行数)

????小贴士

information_schema.tables 中,提供了对表行数的估算,比起使用 select count(1) 的成本低很多,几乎可以忽略不计。

那么是不是所有的 update,从引擎中获取的行数都会是表大小的两倍呢?这个还是要分情况讨论的,上面的 SQL 更新了主键,如果只更新内容而不更新主键呢?我们来试验一下:

等待 update 结束,查看 row_examined,发现其刚好是表大小:

那我们怎么准确的这个倍数呢?

一种方法是靠经验:update 语句的 where 中会扫描多少行,是否修改主键,是否修改唯一键,以这些条件来估算系数。

另一种方法就是在同样结构的较小的表上试验一下,获取倍数。

这样,我们就能准确估算一个大型 update 的进度了。

如何查询MySql日志

1.首先确认你日志是否启用了

MySQLshow variables like 'log_bin';

2.如果启用了,即ON那日志文件就在MySQL的安装目录的data目录下

3.怎样知道当前的日志

MySQL show master status;

4.看二进制日志文件用MySQLbinlog

shellMySQLbinlog mail-bin.000001

或者

shellMySQLbinlog mail-bin.000001 | tail 因为mail-bin.000001是二进制的日志,所以想看日志就需要用mysqlbinlog命令,将二进制文件转换为日志文件,下面详细说说如何使用:上面已经说过如果启用了日志文件,那么默认的日志文件就在data目录下(如果你没有更改的话)进入存放日志文件目录,使用mysqlbinlog localhost-bin.000202 new_file_name.log

命令,将目标文件保存为日志文件,可指定保存路径下

有个小技巧跟大家介绍下,我在准备转换的时候发现日志文件有2G多,寻思着为什么mysql为什么不把日志按日志定期的分多个文件放呢。结果发现mysql有个更好的方法,可以通过时间参数获取某个时间段的数据,例子如下:mysqlbinlog --start-datetime="2010-11-20 00:00:00" --stop-datetime="2010-11-21 00:00:00"

[hx@localhost data]$ mysqlbinlog

mysqlbinlog Ver 3.0 for pc-linux-gnu at i686

By Monty and Sasha, for your professional use

This software comes with NO WARRANTY: This is free software,

and you are welcome to modify and redistribute it under the GPL licenseDumps a MySQL binary log in a format usable for viewing or for piping to

the mysql command line clientUsage: mysqlbinlog [options] log-files

-d, --database=name List entries for just this database (local log only).

-D, --disable-log-bin

Disable binary log. This is useful, if you enabled

--to-last-log and are sending the output to the same

MySQL server. This way you could avoid an endless loop.

You would also like to use it when restoring after a

crash to avoid duplication of the statements you already

have. NOTE: you will need a SUPER privilege to use this

option.

-f, --force-read Force reading unknown binlog events.

-?, --help Display this help and exit.

-h, --host=name Get the binlog from server.

-o, --offset=# Skip the first N entries.

-p, --password[=name]

Password to connect to remote server.

-P, --port=# Use port to connect to the remote server.

-j, --position=# Deprecated. Use --start-position instead.

--protocol=name The protocol of connection (tcp,socket,pipe,memory).

-r, --result-file=name

Direct output to a given file.

-R, --read-from-remote-server

Read binary logs from a MySQL server

--open_files_limit=#

Used to reserve file descriptors for usage by this

program

-s, --short-form Just show the queries, no extra info.

-S, --socket=name Socket file to use for connection.

--start-datetime=name

Start reading the binlog at first event having a datetime

equal or posterior to the argument; the argument must be

a date and time in the local time zone, in any format

accepted by the MySQL server for DATETIME and TIMESTAMP

types, for example: 2004-12-25 11:25:56 (you should

probably use quotes for your shell to set it properly).

--stop-datetime=name

Stop reading the binlog at first event having a datetime

equal or posterior to the argument; the argument must be

a date and time in the local time zone, in any format

accepted by the MySQL server for DATETIME and TIMESTAMP

types, for example: 2004-12-25 11:25:56 (you should

probably use quotes for your shell to set it properly).

--start-position=# Start reading the binlog at position N. Applies to the

first binlog passed on the command line.

--stop-position=# Stop reading the binlog at position N. Applies to the

last binlog passed on the command line.

-t, --to-last-log Requires -R. Will not stop at the end of the requested

binlog but rather continue printing until the end of the

last binlog of the MySQL server. If you send the output

to the same MySQL server, that may lead to an endless

loop.

-u, --user=name Connect to the remote server as username.

-l, --local-load=name

Prepare local temporary files for LOAD DATA INFILE in the

specified directory.

-V, --version Print version and exit.Variables (--variable-name=value)

and boolean options {FALSE|TRUE} Value (after reading options)

--------------------------------- -----------------------------

database (No default value)

disable-log-bin FALSE

force-read FALSE

host (No default value)

offset 0

port 3306

position 4

read-from-remote-server FALSE

open_files_limit 64

short-form FALSE

socket (No default value)

start-datetime (No default value)

stop-datetime (No default value)

start-position 4

stop-position 18446744073709551615

to-last-log FALSE

user (No default value)

local-load (No default value)2009.09.30 检查一个应用的问题的时候,发现通过 oracle 的 dblink 连接 mysql 进行更新等操作的时候,mysql 不会把操作的 sql 语句记录到日志文件里

怎样查看mysql是否开启日志功能

1、首先确认你日志是否启用了mysqlshow variables like 'log_bin'。

2、如果启用了,即ON,那日志文件就在mysql的安装目录的data目录下。

3、怎样知道当前的日志mysql show master status。

4、看二进制日志文件用mysqlbinlog,shellmysqlbinlog mail-bin.000001或者shellmysqlbinlog mail-bin.000001 | tail,Windows 下用类似的。

MySQL的日志操作:

1、首先,登陆mysql后,执行sql语句:show variables like 'log_bin'。

2、#错误日志log-errol开启方式:在my.ini的[mysqld]选项下:添加代码:log-error=E:\log-error.txt。

记录内容:主要是记录启动、运行或停止mysqld时出现的致命性问题,都是系统级的错误记录。

3、#查询日志:log,开启方式:在my.ini的[mysqld]选项下:添加代码:log=E:/mysql_log.txt。

4、#二进制日志:log-bin,开启方式:在my.ini的[mysqld]选项下:添加代码:log-bin=E:/mysql_log_bin,记录内容:主要是记录所有的更改数据的语句,可使用mysqlbinlog命令恢复数据。


本文名称:mysql安装日志怎么看,怎么查看mysql的运行日志
文章位置:http://cqwzjz.cn/article/dsigies.html