0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLの便利クエリ

0
Last updated at Posted at 2016-03-22

ちょっと便利なクエリについてまとめます。

PORTを確認する

show variables like 'port';

ユーザの一覧を取得する

select User, Host from mysql.user;

現在のデータベース名を表示する

SELECT database();

テーブル一覧を取得する

SHOW TABLES FROM データベース名 LIKE パターン;

※カレントデータベースの場合From句は省略可
※LIKE句による絞込が可能

テーブルのDDLを確認する

SHOW CREATE TABLE テーブル名

テーブルのコメントを確認する

show table status like テーブル名など;

カラムのコメントを確認する

show full columns from テーブル名;

期間の絞込

select * from hoge where hoge_date between now() - interval 10 WEEK and now();
  • 上記の例は直近10週間
  • 日付のみの場合、now()の代わりにcurrent_date()を使う
  • WEEK以外にもSECOND、MINUTE、HOUR、DAY、WEEK、MONTHなどがある

実行計画を見る

explain select * from hoge;

Linuxコマンドを実行する

\! ls

外部SQLを実行する

source test.sql
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?