この内容、あるサイトの解説記事からパクってます。順次更新しないと…
$ su # rpm -ivh ファイルその1.rpm # rpm -ivh ファイルその2.rpm 以下同様…
$ su # cp /usr/share/mysql/my-small.cnf /etc/my.cnf
# vi /etc/my.cnf
[mysqld] default-character-set=ujis
$ mysqlshow
$ su # /etc/init.d/mysql stop
# /etc/init.d/mysql start
$ mysqladmin -u root password '管理パスワード' $ mysql_install_db
$ mysqladmin -u root -p create user_db Enter password: 管理パスワード
$ mysql -u root -p Enter password: 管理パスワード mysql> show databases; +----------+ | Database | +----------+ | mysql | | test | | user_db | +----------+ 3 rows in set (0.00 sec) mysql> exit Bye
$ mysql -u root -p Enter password: 管理パスワード mysql> grant all on *.* to db_user@localhost identified by 'ユーザパスワード'; mysql> flush privileges; mysql> exit Bye
"907-14","907-1432","沖縄県","八重山郡竹富町","古見" "907-15","907-1543","沖縄県","八重山郡竹富町","崎山" "907-14","907-1431","沖縄県","八重山郡竹富町","高那" "907-11","907-1101","沖縄県","八重山郡竹富町","竹富" "907-14","907-1434","沖縄県","八重山郡竹富町","南風見" "907-14","907-1433","沖縄県","八重山郡竹富町","南風見仲" "907-17","907-1751","沖縄県","八重山郡竹富町","波照間" "907-15","907-1544","沖縄県","八重山郡竹富町","鳩間" "907-18","907-1800","沖縄県","八重山郡与那国町","以下に掲載がない場合" "907-18","907-1801","沖縄県","八重山郡与那国町","与那国"
旧番号 新番号 都道府県名 市区郡町村名 町村字名
060 060-0041 北海道 札幌市中央区 大通東
154 154-0002 東京都 世田谷区 下馬
468 468-0039 愛知県 名古屋市天白区 西入町
907-18 907-1801 沖縄県 八重山郡与那国町 与那国 zipcode
名称 内容 型 属性
oldzip 旧番号 text
newzip 新番号 text 空欄不可
pref 都道府県名 text
city 市区郡町村名 text
addr 町字名 text 空欄不可$ mysql -u db_user -p Enter password: ユーザパスワード mysql>
mysql> use user_db; Database changed mysql>
mysql> exit Bye
mysql> use user_db;
mysql> create table zipcode(
-> oldzip text,
-> newzip text not null,
-> pref text,
-> city text,
-> addr text not null
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> show fields from zipcode; +---------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+------+------+-----+---------+-------+ | oldzip | text | YES | | NULL | | | newzip | text | | | | | | pref | text | YES | | NULL | | | city | text | YES | | NULL | | | addr | text | | | | | +---------+------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> drop table zipcode;
mysql> insert into zipcode
-> (oldzip,newzip,pref,city,addr)
-> values('154','154-0002','東京都','世田谷区','下馬');
Query OK, 1 rows affected (0.03 sec)
旧番号 新番号 都道府県名 市区郡町村名 町村字名
060 060-0041 北海道 札幌市中央区 大通東
154 154-0002 東京都 世田谷区 下馬
468 468-0039 愛知県 名古屋市天白区 西入町
907-18 907-1801 沖縄県 八重山郡与那国町 与那国【基本構文】 select フィールド名 from テーブル名 ;
mysql> select newzip,pref from zipcode; +----------+--------+ | newzip | pref | +----------+--------+ | 060-0041 | 北海道 | | 154-0002 | 東京都 | | 468-0039 | 愛知県 | | 907-1801 | 沖縄県 | +----------+--------+ 4 rows in set (0.00 sec)
mysql> select * from zipcode;
mysql> load data infile '/置いてある場所/yubin_euc.csv'
-> into table zipcode fields terminated by ',';
Query OK, 121622 rows affected (0.78 sec)
Records: 121622 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select count(*) from zipcode; +----------+ | count(*) | +----------+ | 121622 | +----------+ 1 row in set (0.00 sec)
【基本構文】 select フィールド名 from テーブル名 where 条件式 ;
複数の行に分けて書くこともできます。
select フィールド名
from テーブル名
where 条件式 ;
select * from zipcode where oldzip='468' ;
select newzip,addr from zipcode where city='世田谷区' ;
select count(*) from zipcode where pref='鳥取県' ;
select * from zipcode where pref='鳥取県' limit 50;
select * from zipcode where pref='滋賀県' && city='草津市' ;
select * from zipcode where city='渋谷区' || city='新宿区' ;
select * from zipcode where city like '%日高%';