Tips

MySQL コマンド その1 【初級編 第6回】

MySQL コマンド その1 【初級編 第6回】

MySQLのコマンド

MySQLクライアントで接続した際に使用できるコマンド

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

shellのコマンドを実行する

mysql> system
または
mysql> ¥!

 例)mysql> ¥! ls / 
 bin boot dev etc home lib lost+found media misc mnt net opt proc root sbin selinux srv sys tmp usr var 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mysqlへの接続の状態を確認する

mysql> status
または
mysql> ¥s

例) mysql> ¥s
————–
mysql Ver 14.14 Distrib 5.1.58, for redhat-linux-gnu (i686) using readline 5.1

Connection id: 187
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less -S -X
Using outfile: ”
Using delimiter: ;
Server version: 5.1.58 MySQL Community Server (GPL) by Utter Ramblings
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 3 days 2 hours 7 min 47 sec

Threads: 1 Questions: 7286 Slow queries: 0 Opens: 1587 Flush tables: 1 Open tables: 64 Queries per second avg: 0.27
————–

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

コマンドのヘルプを表示する

mysql> help

例)mysql> help
For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (¥?) 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.
edit      (¥e) Edit command with $EDITOR.
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.
nopager   (¥n) Disable pager, print to stdout.
notee     (¥t) Don't write into outfile.
pager     (¥P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (¥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.

For server side help, type 'help contents'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
デリミタ(命令の終了文字)を変更する
mysql> delimiter

例) mysql> delimiter //

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

接続しているユーザ名の確認

mysql> select user();

例) mysql> select user();

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

登録されているユーザ名の表示(mysqlというDB内の userというテーブルに格納されている)

mysql> select user,host from mysql.user;

例)mysql> select user,host from mysql.user;

+-----------+-----------------------+
| user      | host                  |
+-----------+-----------------------+
| user01    | %                     |
| user02    | %                     |
| root      | 127.0.0.1             |
| root      | 192.168.0.200         |
|           | localhost             |
| root      | localhost             |
| testuser  | localhost             |
|           | localhost.localdomain |
| root      | localhost.localdomain |
+-----------+-----------------------+
9 rows in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

接続を抜ける

mysql> ¥q
または
mysql> quit
または
mysql> exit

例)mysql> ¥q
[root@webserver html]#

以上です。

SQLが学べる 関連連載リンク

データベースの基礎が学べるSQL基礎講座
SQL基礎 連載

練習問題を通じてSQL理解度アップの人気連載!
SQL練習問題集

Recent News

Recent Tips

Tag Search