はじめてMySQLを使ってみる
はじめてMySQLを使ってみる
0.改訂履歴
1.はじめに
このドキュメントでは,MacOS Xにインストールした,MySQL 4.1.12を初心者が使ってみるログである.
2.いろいろ使ってみる
- rootユーザで接続してみる.
- mysqlといのうが,SQL*Plusやisqlのようなコマンドラインツールのようです.
ivory:/usr/local/mysql/bin shinnai$ ./mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 4.1.12-max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
|
- バージョンを表示させてみる.
- 実行用の区切り文字は,Oracleと同じ;の様です.
mysql> select version() -> ;
+------------+
| version() |
+------------+
| 4.1.12-max |
+------------+
1 row in set (0.30 sec)
mysql>
|
mysql> select current_date;
+--------------+
| current_date |
+--------------+
| 2005-05-30 |
+--------------+
1 row in set (0.26 sec)
mysql>
|
mysql> select 1000+25; +---------+ | 1000+25 | +---------+ | 1025 | +---------+ 1 row in set (0.26 sec)
mysql>
|
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2005-05-30 14:05:23 |
+---------------------+
1 row in set (0.10 sec)
mysql>
|
- きっとformat()関数みたいなので,加工できるに違いない.
- 現在ログインしているユーザアカウントの表示.
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.18 sec)
mysql>
|
mysql> help;
For the complete MySQL Manual online, visit:
http://www.mysql.com/documentation
For info on technical support from MySQL developers, visit:
http://www.mysql.com/support
For info on MySQL books, utilities, consultants, etc., visit:
http://www.mysql.com/portal
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear command.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set query 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 a 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.
For server side help, type 'help contents'
mysql>
|
mysql> show databases;
+----------+
| Database |
+----------+
| mysql | | test | +----------+ 2 rows in set (0.03 sec)
mysql>
|
- 動作させているOSによって,このデータベースは別のものが含まれている事があるそうですが.
- データベースを移動してみる.
mysql> use test
Database changed
mysql> use mysql 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>
|
- mysqlデータベースに移動したときには,テーブルとカラム名を呼び出しましたというメッセージが出ており,(mysqlを)起動する際に-Aをつける事で高速化できるそうだ.
- データベースを作成してみる.
mysql> create database test2 -> ; Query OK, 1 row affected (0.07 sec)
mysql> show databases; +----------+ | Database | +----------+ | mysql | | test | | test2 | +----------+ 3 rows in set (0.00 sec)
mysql> use test2
Database changed
mysql>
|
- リストに1つ増えた事が解る.
- 物理ファイル等との関係が,この時点で解ってないので,何が実際で来たのかは不明.
- 瞬時に作成できたので,予測するにエントリーポイントだけ定義されたのかも.
- データベースの状態をみてみる.
mysql> status
--------------
./mysql Ver 14.7 Distrib 4.1.12, for apple-darwin7.9.0 (powerpc) using
readline 4.3
Connection id: 5
Current database: test2
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 4.1.12-max
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /tmp/mysql.sock
Uptime: 5 hours 55 min 45 sec
Threads: 1 Questions: 71 Slow queries: 0 Opens: 26 Flush tables: 1 O pen tables: 15 Queries per second avg: 0.003
--------------
mysql>
|
- キャラクタセットが,latain1になっている.つまりヨーロッパ系言語体系用という事です.
- これは後でどうにかしないとなぁ.
- どんなテーブルがあるか確認する.
mysql> show tables; Empty set (0.00 sec)
mysql>
|
- 作成したばかりのデータベース内には,何もテーブルが無い.
- 1つダミーのテーブルを作成してみる.
mysql> create table test_tbl (a char(10),b varchar(20)); Query OK, 0 rows affected (0.14 sec)
mysql> show tables;
+-----------------+
| Tables_in_test2 |
+-----------------+
| test_tbl |
+-----------------+
1 row in set (0.00 sec)
mysql>
|
- mysqlデータベース上に何があるのか,みてみたくなったので確認してみる.
mysql> use mysql 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_mysql | +---------------------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 15 rows in set (0.00 sec)
mysql>
|
mysql> describe help_topic
-> ;
+------------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------+-------+
| help_topic_id | int(10) unsigned | | PRI | 0 | |
| name | varchar(64) | | UNI | | |
| help_category_id | smallint(5) unsigned | | | 0 | |
| description | text | | | | |
| example | text | | | | |
| url | varchar(128) | | | | |
+------------------+----------------------+------+-----+---------+-------+
6 rows in set (0.09 sec)
mysql>
|