コマンドの入力と実行

広告

MySQLコマンドラインツールを起動しMySQLサーバへ接続すると、任意のSQL文を実行することができます。またSQL文を実行するだけではなく、用意されたコマンドを実行することもできます。ここではコマンドの実行方法について確認します。

まずはMySQLコマンドラインツールを起動して下さい。

p4-1

次のようなプロンプトが表示されます。

mysql>

この状態からSQL文を入力したりコマンドを入力します。コマンドを入力する時は次のように行います。

mysql> コマンド名

コマンド名を入力した後でEnterキーを押して実行して下さい。では例として「status」コマンドを実行してみます。

p4-2

p4-3

コマンドの種類によりますが、何らかの結果を画面に出力した後で入力待ちの状態となります。

コマンドの種類

ではどのようなコマンドが用意されているか確認してみます。「help」コマンドを実行して下さい。

p4-4

コマンドの一覧と簡単な説明が表示されます。出力された内容をまとめたものを次にまとめました。

コマンド名短縮形説明
?¥?Synonym for `help'.
clear¥cClear the current input statement.
connect¥rReconnect to the server. Optional arguments are db and host.
delimiter¥dSet statement delimiter.
ego¥GSend command to mysql server, display result vertically.
exit¥qExit mysql. Same as quit.
go¥gSend command to mysql server.
help¥hDisplay this help.
notee¥tDon't write into outfile.
print¥pPrint current command.
prompt¥RChange your mysql prompt.
quit¥qQuit mysql.
rehash¥#Rebuild completion hash.
source¥.Execute an SQL script file. Takes a file name as an argument.
status¥sGet status information from the server.
tee¥TSet outfile [to_outfile]. Append everything into given outfile.
use¥uUse another database. Takes database name as argument.
charset¥CSwitch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings¥WShow warnings after every statement.
nowarning¥wDon't show warnings after every statement.

各コマンドは通常のものと短縮形がありどちらを使って頂いても同じです。例えばコマンドラインツールを終了するには「quit」と入力して頂いても「¥q」と入力しても同じです。

mysql> quit
mysql> ¥q

( Written by Tatsuo Ikura )