网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

mysql查询日志的命令

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

创新互联专注于企业成都全网营销推广、网站重做改版、驿城网站定制设计、自适应品牌网站建设、H5开发购物商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为驿城等各大城市提供网站开发制作服务。

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查询日志的命令”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


文章题目:mysql查询日志的命令
文章起源:http://bjjierui.cn/article/pepggc.html

其他资讯