10 KiB
10 KiB
title | author | date | url | wordtwit_post_info | categories | |||
---|---|---|---|---|---|---|---|---|
MySQLを触ってみた | kazu634 | 2009-07-07 | /2009/07/07/_1291/ |
|
|
スクレイピングした結果をデータベースに格納してみようと思い立ちました。というわけで、MySQLを触ることに。
サンプルのデータベース・テーブルの作り方
kazu634@kazu634-desktop% mysql -u root -p ~ [2961] Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 45 Server version: 5..75-0ubuntu10.2 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (.01 sec) mysql> create database sample; Query OK, 1 row affected (.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | sample | +--------------------+ 3 rows in set (.00 sec) mysql> USE sample Database changed mysql> SHOW TABLES; Empty set (.00 sec) mysql> CREATE TABLE Prefecture( -> PREF_CD INT(3), -> PREF_NAME VARCHAR(10), -> PRIMARY KEY (PREF_CD) -> ); Query OK, rows affected (.01 sec) mysql> SHOW TABLES+ -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+' at line 1 mysql> SHOW TABLES; +------------------+ | Tables_in_sample | +------------------+ | Prefecture | +------------------+ 1 row in set (.00 sec) mysql> DESC Prefecture -> ; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | PREF_CD | int(3) | NO | PRI | | | | PREF_NAME | varchar(10) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 2 rows in set (.01 sec) mysql> exit; Bye
次は
『モダンPerl入門 (CodeZine BOOKS)』でデータベースを使うための方法を確認するぞ。