11
4

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 1 year has passed since last update.

MySQL | ワンライナーをコンソールに委ねて楽をしよう

Last updated at Posted at 2016-06-11

問題

たとえばテーブル定義を確認する場合。

毎回 mysql モードに入って、 use でデータベース名を指定して、テーブル名を手打ちしたり。
コンソールで別窓を立ち上げたりしていないだろうか。

これはとても面倒だ。

解決

よく使うコマンド等は linux コマンドに任せてしまおう。
-e オプションでワンライナーが書ける。

$ mysql -e "USE your_database; DESC your_table;"

+--------------+---------------------+------+-----+---------+-------+
| Field        | Type                | Null | Key | Default | Extra |
+--------------+---------------------+------+-----+---------+-------+
| ID           | bigint(20) unsigned | NO   | PRI | 0       |       |
| Name         | varchara(255)       | NO   |     |         |       |
+--------------+---------------------+------+-----+---------+-------+

良いところ

  • コンソールのコマンド履歴がそのまま使える。
    • 上下キーで履歴をたどるのは勿論のこと。
    • $ historyC-r も使えるし。 コンソールで出来ることはなんでも出来る。
  • コンソールを mysql モードを切り替える必要がない。

環境

  • mysql Ver 14.14 Distrib 5.5.44, for osx10.10 (x86_64) using EditLine wrapper

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

11
4
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
11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?