環境は MySQL 5.0 系 on Debian GNU/Linux 5.0 lenny.

MySQL monitor を起動(ログイン)。


$ mysql -u ユーザー名 -p

データベース一覧を表示。


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| hogedb             | 
+--------------------+
2 rows in set (0.00 sec)

使用するデータベースを選択。


mysql> use hogedb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed

テーブル一覧を表示。


mysql> show tables;
+--------------------+
| Tables_in_hogedb    |
+--------------------+
| aaatable           | 
| bbbtable           | 
| ccctable           | 
+--------------------+
3 rows in set (0.00 sec)

テーブルのカラム情報を表示。


mysql> show columns from aaatable;
+------------+------------+------+-----+-------------------+-------+
| Field      | Type       | Null | Key | Default           | Extra |
+------------+------------+------+-----+-------------------+-------+
| ckey       | text       | NO   | MUL | NULL              |       | 
| cvalue     | mediumtext | NO   |     | NULL              |       | 
| cachedtime | timestamp  | NO   | MUL | CURRENT_TIMESTAMP |       | 
| expirytime | timestamp  | YES  |     | NULL              |       | 
+------------+------------+------+-----+-------------------+-------+
4 rows in set (0.03 sec)

レコード数を表示。


mysql> select count(*) from aaatable;
+----------+
| count(*) |
+----------+
|   480952 | 
+----------+
1 row in set (0.00 sec)

条件を指定してレコードを表示。


mysql> select ckey, cachedtime from aaatable where cachedtime < "2012-01-21" order by cachedtime desc limit 3;
+----------------------------------------------------------------+---------------------+

| ckey                                                           | cachedtime          |

+--------------------------------------------------------------------------------------+
| http://www.nilab.info/gs/v1/?Count=100                         | 2012-01-20 23:59:59 |
| http://www.nilab.info/gs/V1/?l
l=35.06881,137.03286&Range=5 | 2012-01-20 23:59:55 |
| http://www.nilab.info/hs/V1/?x=493328931                       | 2012-01-20 23:59:55 |
+--------------------------------------------------------------------------------------+
3 rows in set (0.07 sec)

テーブルのインデックスを表示。


mysql> show index from aaatable;
+----------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table    | Non_unique | Key_name                 | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| aaatable |          1 | i_key                    |            1 | ckey        | A         |      480961 |      255 | NULL   |      | BTREE      |         | 
| aaatable |          1 | idx_aaatable_chachedtime |            1 | cachedtime  | A         |      240480 |     NULL | NULL   |      | BTREE      |         | 
+----------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (0.02 sec)

MySQL monitor を終了(ログアウト)。


mysql> exit
Bye

Ref.
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 7 クライアントプログラムとユーティリティ プログラム
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 7.7 mysql — MySQL コマンド ライン ツール
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 10 データタイプ
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 12 SQL ステートメント構文
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 12.2.7 SELECT 構文
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 12.2.1 DELETE 構文
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 12.5.4.4 SHOW COLUMNS 構文
- MySQL :: MySQL 5.1 リファレンスマニュアル :: 12.5.4.17 SHOW INDEX 構文
- MySQL :: MySQL 4.1 リファレンスマニュアル :: 6 MySQL SQL言語リファレンス
- MySQL :: MySQL 4.1 リファレンスマニュアル :: 6.4 データの操作: SELECT、INSERT、UPDATE、DELETE
- MySQL :: MySQL 4.1 リファレンスマニュアル :: 6.5 データ定義: CREATE、DROP、ALTER
- MySQL メモ (MySQL - MemoWiki)

tags: mysql

Posted by NI-Lab. (@nilab)