Skip to content

Instantly share code, notes, and snippets.

@studio3104
Last active December 12, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save studio3104/4736167 to your computer and use it in GitHub Desktop.
Save studio3104/4736167 to your computer and use it in GitHub Desktop.
mysql> use information_schema
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 SLEEP(2);
+----------+
| SLEEP(2) |
+----------+
| 0 |
+----------+
1 row in set (2.00 sec)
mysql> SELECT SLEEP(2);
+----------+
| SLEEP(2) |
+----------+
| 0 |
+----------+
1 row in set (2.00 sec)
mysql> use mysql
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 SLEEP(2);
+----------+
| SLEEP(2) |
+----------+
| 0 |
+----------+
1 row in set (2.00 sec)
mysql>
long_query_time = 2
example.sqlのようなオペレーションをすると、slow_query.logみたいな感じでスロークエリログが出ますよね。
use句でデータベースを切り替えると、スロークエリログにもuse句が出ますが、一度use句が出たらデータベースが切り替わってスロークエリログが吐かれるまでは二度とスロークエリログにuse句は出ないですよね?
現在選択されているデータベース名を取得する方法って何かないでしょうか?
スロークエリログを参照せずに最後にどのデータベースへのクエリがスロークエリログに出たのか、というか・・・
コレをRubyのプログラムから取得したいのです。
# Time: 130208 11:19:24
# User@Host: root[root] @ localhost []
# Query_time: 2.000338 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
use information_schema;
SET timestamp=1360289964;
SELECT SLEEP(2);
# Time: 130208 11:19:33
# User@Host: root[root] @ localhost []
# Query_time: 2.000321 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1360289973;
SELECT SLEEP(2);
# Time: 130208 11:19:43
# User@Host: root[root] @ localhost []
# Query_time: 2.000320 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
use mysql;
SET timestamp=1360289983;
SELECT SLEEP(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment