MySQL 公式のサンプルデータを使用する

  • 作成日 2022.02.08
  • 更新日 2022.10.17
  • mysql
MySQL 公式のサンプルデータを使用する

MySQLで、公式のサンプルデータを使用する手順を記述してます。

環境

  • OS ubuntu21.10
  • MySQL Ver 8.0.27-0ubuntu0.21.10.1 for Linux on x86_64 (Ubuntu)

手順

まずはこちらのサイトからファイルをダウンロードします。

ここでは「world database」をダウンロードして、インポートしていきます。

まずはログインします。

$ mysql -u root -p

wgetを使って入手します。

mysql> system wget https://downloads.mysql.com/docs/world-db.tar.gz

downloads.mysql.com (downloads.mysql.com) をDNSに問いあわせています... 137.254.60.14
downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 92914 (91K) [application/x-gzip]
‘world-db.tar.gz’ に保存中

world-db.tar.gz                   100%[==========================================================>]  90.74K   128KB/s    in 0.7s 

解凍します。

mysql> system tar -zxvf world-db.tar.gz;
world-db/
world-db/world.sql

インポートを行います。

mysql> SOURCE world-db/world.sql

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

これでインポートが終わって、データベースが追加されたことが確認できます。

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| stored_test        |
| sys                |
| testdb             |
| world              |
+--------------------+

以下の3つのテーブルが存在します。

mysql> USE world;
Database changed

mysql> SHOW TABLES;
+-----------------+
| Tables_in_world |
+-----------------+
| city            |
| country         |
| countrylanguage |
+-----------------+
3 rows in set (0.00 sec)

各データ

各データは以下の通りになります。