コマンド一覧

パラメータ

一覧

パラメータ 内容
-u <ユーザーID> ユーザーIDを指定
-p パスワードをプロンプトで入力
--password=<パスワード> パスワードを指定
--execute= SQLを指定
--database=<データベース> データベース名を指定
--host=<ホスト名> ホスト名、IPアドレス指定
--port=<ポート番号> ポート番号指定

詳細は「mysql --help」と押下

MySQLクライアント

サーバへ接続

パスワードをコマンドで入力
C:\>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.47-community MySQL Community Server (GPL)
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>\q
Bye
 
C:\>
 
Enter password: ********でパスワードを設定する


パスワードをコマンドで入力
C:\>mysql -u root --password=password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.47-community MySQL Community Server (GPL)
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>\q
Bye
 
C:\>
 
mysql -u root --password=password

サーバを切断

\q、quit、exit、[CTRL+C]のどれかをキーを入力
mysql>\q
Bye
 
C:\>
 

接続情報を表示

\sでキー入力
mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.1.47, for Win32 (ia32)
 
Connection id:          6
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.1.47-community MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
TCP port:               3306
Uptime:                 5 hours 51 min 57 sec
 
Threads: 1  Questions: 10  Slow queries: 0  Opens: 15  Flush tables: 1  Open tab
les: 0  Queries per second avg: 0.0
--------------
 
mysql>
 

データベースを選択

USE データベース名 の選択
mysql> use testdb1;
Database changed
mysql>
 
MySQLはデータベースを選択する必要があるのでこの処理が必要

SQLを実行

mysql> insert into testtable1(data1, data2, data3)
    ->    values('000001', 'aaaaa', 'aaaaa-1');
Query OK, 1 row affected (0.11 sec)
 
mysql> insert into testtable1(data1, data2, data3)
    ->    values('000002', 'aaaaa', 'aaaaa-2');
Query OK, 1 row affected (0.04 sec)
 
mysql> select * from testtable1;
+--------+-------+---------+
| data1  | data2 | data3   |
+--------+-------+---------+
| 000001 | aaaaa | aaaaa-1 |
| 000002 | aaaaa | aaaaa-2 |
+--------+-------+---------+
2 rows in set (0.09 sec)
 
mysql>
 

MySQLコマンド

SQLコマンドを直接実行

c:\>mysql -u root --password=password --database=testdb1 --execute="select * from testtable1;"
+--------+-------+---------+
| data1  | data2 | data3   |
+--------+-------+---------+
| 000001 | aaaaa | aaaaa-1 |
| 000002 | aaaaa | aaaaa-2 |
+--------+-------+---------+
 
c:\>
 

SQLファイルを実行

c:\>mysql -u root -t --password=password --database=testdb1 < testtable1.SQL
+--------+-------+---------+
| data1  | data2 | data3   |
+--------+-------+---------+
| 000001 | aaaaa | aaaaa-1 |
| 000002 | aaaaa | aaaaa-2 |
+--------+-------+---------+
 
c:\>
 
testtable1.SQLの内容
select * from testtable1;
 
最終更新:2010年06月22日 16:17