LoginSignup
2
0

More than 5 years have passed since last update.

MariaDB MySQL 都道府県の入力sample

Last updated at Posted at 2018-02-13

都道府県の入力、確認までのサンプル

プロンプトは、

MariaDB [login]> 

以下のクエリを一度テキストにコピーして
多少自分なりに変更してからペーストすることをオススメします。
ログインは、

terminal
$ sudo mysql

DBの作成

mysql
create database test_db;

作成したDBに移動

mysql
use test_db

最後のセミコロンいりません。

Userの作成

mysql
grant select on test_db.* to 'user'@'localhost' identified by {パスワード};

Tableの作成

mysql
create table States(
  id int not null auto_increment primary key,
  state text,
  created datetime
);

idを自動で増加するprimary keyにすること
created(制作日時)を入れるのが定石?らしいです。

内容の挿入

mysql
insert into States (state, created) values
('北海道', now()),
('青森県', now()),
('岩手県', now()),
('宮城県', now()),
('秋田県', now()),
('山形県', now()),
('福島県', now()),
('茨城県', now()),
('栃木県', now()),
('群馬県', now()),
('埼玉県', now()),
('千葉県', now()),
('東京都', now()),
('神奈川県', now()),
('新潟県', now()),
('富山県', now()),
('石川県', now()),
('福井県', now()),
('山梨県', now()),
('長野県', now()),
('岐阜県', now()),
('静岡県', now()),
('愛知県', now()),
('三重県', now()),
('滋賀県', now()),
('京都府', now()),
('大阪府', now()),
('兵庫県', now()),
('奈良県', now()),
('和歌山県', now()),
('鳥取県', now()),
('島根県', now()),
('岡山県', now()),
('広島県', now()),
('山口県', now()),
('徳島県', now()),
('香川県', now()),
('愛媛県', now()),
('高知県', now()),
('福岡県', now()),
('佐賀県', now()),
('長崎県', now()),
('熊本県', now()),
('大分県', now()),
('宮崎県', now()),
('鹿児島県', now()),
('沖縄県', now());

idは、自動で1からカウントしてくれます。
沖縄が47です。

tableの形式の確認

mysql
desc States;

tableの内容の確認

mysql
select * from States;

結果

mysql
MariaDB [login]> select * from States;
+----+--------------+---------------------+
| id | state        | created             |
+----+--------------+---------------------+
|  1 | 北海道        | 2018-02-13 19:35:13 |
|  2 | 青森県        | 2018-02-13 19:35:13 |
|  3 | 岩手県        | 2018-02-13 19:35:13 |
|  4 | 宮城県        | 2018-02-13 19:35:13 |
|  5 | 秋田県        | 2018-02-13 19:35:13 |
|  6 | 山形県        | 2018-02-13 19:35:13 |
|  7 | 福島県        | 2018-02-13 19:35:13 |
|  8 | 茨城県        | 2018-02-13 19:35:13 |
|  9 | 栃木県        | 2018-02-13 19:35:13 |
| 10 | 群馬県        | 2018-02-13 19:35:13 |
| 11 | 埼玉県        | 2018-02-13 19:35:13 |
| 12 | 千葉県        | 2018-02-13 19:35:13 |
| 13 | 東京都        | 2018-02-13 19:35:13 |
| 14 | 神奈川県      | 2018-02-13 19:35:13 |
| 15 | 新潟県        | 2018-02-13 19:35:13 |
| 16 | 富山県        | 2018-02-13 19:35:13 |
| 17 | 石川県        | 2018-02-13 19:35:13 |
| 18 | 福井県        | 2018-02-13 19:35:13 |
| 19 | 山梨県        | 2018-02-13 19:35:13 |
| 20 | 長野県        | 2018-02-13 19:35:13 |
| 21 | 岐阜県        | 2018-02-13 19:35:13 |
| 22 | 静岡県        | 2018-02-13 19:35:13 |
| 23 | 愛知県        | 2018-02-13 19:35:13 |
| 24 | 三重県        | 2018-02-13 19:35:13 |
| 25 | 滋賀県        | 2018-02-13 19:35:13 |
| 26 | 京都府        | 2018-02-13 19:35:13 |
| 27 | 大阪府        | 2018-02-13 19:35:13 |
| 28 | 兵庫県        | 2018-02-13 19:35:13 |
| 29 | 奈良県        | 2018-02-13 19:35:13 |
| 30 | 和歌山県      | 2018-02-13 19:35:13 |
| 31 | 鳥取県        | 2018-02-13 19:35:13 |
| 32 | 島根県        | 2018-02-13 19:35:13 |
| 33 | 岡山県        | 2018-02-13 19:35:13 |
| 34 | 広島県        | 2018-02-13 19:35:13 |
| 35 | 山口県        | 2018-02-13 19:35:13 |
| 36 | 徳島県        | 2018-02-13 19:35:13 |
| 37 | 香川県        | 2018-02-13 19:35:13 |
| 38 | 愛媛県        | 2018-02-13 19:35:13 |
| 39 | 高知県        | 2018-02-13 19:35:13 |
| 40 | 福岡県        | 2018-02-13 19:35:13 |
| 41 | 佐賀県        | 2018-02-13 19:35:13 |
| 42 | 長崎県        | 2018-02-13 19:35:13 |
| 43 | 熊本県        | 2018-02-13 19:35:13 |
| 44 | 大分県        | 2018-02-13 19:35:13 |
| 45 | 宮崎県        | 2018-02-13 19:35:13 |
| 46 | 鹿児島県      | 2018-02-13 19:35:13 |
| 47 | 沖縄県        | 2018-02-13 19:35:13 |
+----+--------------+---------------------+
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0