my sql 有相似Sql Server Profiler的工具吗?

MySql 码拜 8年前 (2016-02-07) 976次浏览
本人用.net 项目调用my sql 实现事务操作,但回滚无效,
本人想看看真实执行了些什么sql语句。
解决方案

10

假如server是开发本人用的,可以考虑general_log记录全部sql。

set global general_log = on;
执行你的程序
set global general_log = off;

相应的sql会记录在 select @@global.general_log_file 指定的文件里

30

引用 4 楼 yupeigu 的回复:
Quote: 引用 2 楼 jvhmr 的回复:
Quote: 引用 1 楼 gikod 的回复:

假如server是开发本人用的,可以考虑general_log记录全部sql。

set global general_log = on;
执行你的程序
set global general_log = off;

相应的sql会记录在 select @@global.general_log_file 指定的文件里

这个是记录全部连接到这个my sql 的全部程序的sql命令,
还是只记录规定范围的sql 命令?

全部的
不过你可以把这些数据插入到表里,然后直接从表里查询

假如你的server同时会有别人用,这样筛选出你本人的sql。

MariaDB [mysql]> set log_output = "table";
ERROR 1229 (HY000): Variable "log_output" is a GLOBAL variable and should be set with SET GLOBAL
MariaDB [mysql]> set global log_output = "table";
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select "a";
+--+
| a |
+--+
| a |
+--+
1 row in set (0.00 sec)
MariaDB [mysql]> set global general_log=on;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select "a";
+--+
| a |
+--+
| a |
+--+
1 row in set (0.01 sec)
MariaDB [mysql]> set global general_log=off;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> set global log_output="file";
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log;
+--+--+--+--+--+--+
| event_time          | user_host                    | thread_id | server_id | command_type | argument                   |
+--+--+--+--+--+--+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] |         3 |         1 | Query        | select "a"                 |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] |         3 |         1 | Query        | set global general_log=off |
+--+--+--+--+--+--+
2 rows in set (0.00 sec)
MariaDB [mysql]> show columns from mysql.general_log;
+--+--+--+--+--+--+
| Field        | Type                | Null | Key | Default           | Extra                       |
+--+--+--+--+--+--+
| event_time   | timestamp           | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| user_host    | mediumtext          | NO   |     | NULL              |                             |
| thread_id    | bigint(21) unsigned | NO   |     | NULL              |                             |
| server_id    | int(10) unsigned    | NO   |     | NULL              |                             |
| command_type | varchar(64)         | NO   |     | NULL              |                             |
| argument     | mediumtext          | NO   |     | NULL              |                             |
+--+--+--+--+--+--+
6 rows in set (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log where user_host = "root[root] @ localhost [::1]" and thread_id = 3;
+--+--+--+--+--+--+
| event_time          | user_host                    | thread_id | server_id | command_type | argument                   |
+--+--+--+--+--+--+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] |         3 |         1 | Query        | select "a"                 |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] |         3 |         1 | Query        | set global general_log=off |
+--+--+--+--+--+--+
2 rows in set (0.04 sec)

注意不要在生产环境上用,会有附加的开销。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明my sql 有相似Sql Server Profiler的工具吗?
喜欢 (0)
[1034331897@qq.com]
分享 (0)