mysql查询日志的命令

发布时间:2021-09-16 16:37:44 作者:chen
来源:亿速云 阅读:194

这篇文章主要介绍“mysql查询日志的命令”,在日常操作中,相信很多人在mysql查询日志的命令问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”mysql查询日志的命令”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

mysql查询日志是用来记录用户登录数据库、记录用户在数据库操作的日志。类似oracle的审计功能,但是出于线上数据库频繁的操作,会产生大量的IO和磁盘空间的压力,mysql是默认关闭的。但是有时候出于安全的考虑需要开启,这就要在安全和效率之间权衡了。
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name    | Value                                  |
+------------------+----------------------------------------+
| general_log      | OFF                                     |                        --关闭状态
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log |            --查询日志名称
+------------------+----------------------------------------+
2 rows in set (0.00 sec)

mysql>set global general_log=on;
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name    | Value                                  |
+------------------+----------------------------------------+
| general_log      | ON                                    |                          --开启状态
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log |            --查询日志名称
+------------------+----------------------------------------+

现在来看看这些查询日志都有哪些信息
登录数据库进行一番操作
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h272.30.249.154 -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'172.30.248.18' (using password: YES)    --- 登录失败
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h272.30.249.154 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.6.27-76.0-log Percona Server (GPL), Release 76.0, Revision 5498987
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;                                                                                                               -- 选择数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from emp;                                                                                                 --查询
+------+------+
| id   | name |
+------+------+
|    1 | jx   |
+------+------+
1 row in set (0.00 sec)
mysql> drop table emp;                                                                                                     -- 删除
Query OK, 0 rows affected (0.04 sec)
mysql> ^CCtrl-C -- exit!                                                                                                      --退出
Aborted
[root@trcloud-wujian-test01 mysql]
打开查询日志
[root@trcloud-gtt-test-db mysql]# tail -50f trcloud-gtt-test-db.log
160412 14:18:45   190 Connect   root@172.30.248.18 on                                                     --从哪个IP用什么用户登录失败记录
                  190 Connect   Access denied for user 'root'@'172.30.248.18' (using password: YES)
160412 14:19:12   191 Connect   root@172.30.248.18 on                                                     --记录从哪个IP哪个用户何时登录,191是一个session的唯一表示,同一个session这个数字是一致的
                  191 Query     select @@version_comment limit 1
160412 14:19:24   191 Query     SELECT DATABASE()                                                          
                  191 Init DB   test
                  191 Query     show databases
                  191 Query     show tables
                  191 Field List        emp 
160412 14:19:33   191 Query     select * from emp                                                               --查询操作
160412 14:19:40   191 Query     drop table emp                                                                   --删除操作
160412 14:20:18   191 Quit                                                                                               --退出session

到此,关于“mysql查询日志的命令”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. MySQL慢查询日志
  2. mysql慢查询日志是什么

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:javascript如何获取隐藏元素的高度

下一篇:如何实现一个PHP验证码类

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》