MySQLコマンドの一覧とコマンドの実行
MySQL コマンドラインツールを起動すると SQL 文を実行することができますが、他にも MySQL コマンドと呼ばれるコマンドがいくつか用意されています。ここでは MySQL コマンドの一覧とコマンドの実行方法について解説します。
(Last modified: )
MySQLコマンドの一覧
コマンドプロンプトから MySQL に接続し、 MySQL コマンドラインツールを起動してください。
用意されている MySQL コマンドの一覧を表示するには help; と実行してください。
help;
コマンドの一覧が表示されました。
表示された コマンドの一覧と説明は次のようなものです。
| コマンド名 | 短縮形 | 説明 |
|---|---|---|
| ? | \? | Synonym for `help'. |
| clear | \c | Clear the current input statement. |
| connect | \r | Reconnect to the server. Optional arguments are db and host. |
| delimiter | \d | Set statement delimiter. |
| ego | \G | Send command to mysql server, display result vertically. |
| exit | \q | Exit mysql. Same as quit. |
| go | \g | Send command to mysql server. |
| help | \h | Display this help. |
| notee | \t | Don't write into outfile. |
| \p | Print current command. | |
| prompt | \R | Change your mysql prompt. |
| quit | \q | Quit mysql. |
| rehash | \# | Rebuild completion hash. |
| source | \. | Execute an SQL script file. Takes a file name as an argument. |
| status | \s | Get status information from the server. |
| system | \! | Execute a system shell command. |
| tee | \T | Set outfile [to_outfile]. Append everything into given outfile. |
| use | \u | Use another database. Takes database name as argument. |
| charset | \C | Switch to another charset. Might be needed for processing binlog with multi-byte charsets. |
| warnings | \W | Show warnings after every statement. |
| nowarning | \w | Don't show warnings after every statement. |
| resetconnection | \x | Clean session context. |
各コマンドは通常のものと短縮形がありどちらを使って頂いても同じです。例えば MySQL コマンドラインツールを終了する時に使用する quit コマンドは quit と実行しても \q と実行しても同じ結果となります。
quit;
\q
MySQLコマンドの実行方法
MySQL コマンドラインツールの画面から MySQL コマンドを実行するには次のように行います。
mysql> コマンド名;
コマンド名の最後にはセミコロン(;)を付けてください。(ただ実際には省略しても問題ないようです)。
例として status コマンドを実行してみます。
mysql> status;
status コマンドが実行されました。
-- --
MySQL コマンドの一覧とコマンドの実行方法について解説しました。
( Written by Tatsuo Ikura )
著者 / TATSUO IKURA
これから IT 関連の知識を学ばれる方を対象に、色々な言語でのプログラミング方法や関連する技術、開発環境構築などに関する解説サイトを運営しています。