LoginSignup
1
1

MySQLのサンプルデータベース一覧

Last updated at Posted at 2023-12-10

MySQLの学習・検証時に使用できるデータソースです。
Linuxターミナルでのダウンロード方法も記載しています。
デスクトップ環境の場合はソースからダウンロードできます。

■Employees

社員マスター

ソース

ダウンロード

curl -sLO https://github.com/datacharmer/test_db/releases/download/v1.0.7/test_db-1.0.7.tar.gz
tar -zxvf ./test_db-1.0.7.tar.gz

リストア

解凍先に移動しないとリストアが失敗します

cd test_db
mysql -t < employees.sql -u root -p

ER図

employees.png

■sakila

DVD レンタル ストアを表すように設計されています

ソース

ExampleDatabaseからダウンロード

ダウンロード

curl -O https://downloads.mysql.com/docs/sakila-db.tar.gz
tar -zxvf ./sakila-db.tar.gz 

リストア

MySQLインストーラからリストアすることも可能
1.png

mysql -u root -p
Enter password: **********
mysql> SOURCE /usr/src/sakila-db/sakila-schema.sql;
mysql> SOURCE /usr/src/sakila-db/sakila-data.sql;

ER図

sakila.png

■World

世界の国と都市に関する情報を含む一連のテーブルを提供します

ソース

ExampleDatabaseからダウンロード

ダウンロード

curl -O https://downloads.mysql.com/docs/world-db.tar.gz
tar -zxvf ./world-db.tar.gz 

リストア

MySQLインストーラからリストアすることも可能
1.png

mysql -u root -p
Enter password: **********
mysql>  SOURCE /usr/src/world-db/world.sql;

ER図

world.png

備考

亜種:一部ドキュメントテーブルにしている

■menagerie

動物園のDB

ソース

ExampleDatabaseからダウンロード

ダウンロード

curl -O https://downloads.mysql.com/docs/menagerie-db.tar.gz
tar -zxvf ./menagerie-db.tar.gz 

リストア

cd menagerie-db/
mysql -u root -p --local-infile=on
Enter password: **********
mysql> create database menagerie;
mysql> use menagerie;
mysql> SET GLOBAL local_infile=on;
mysql> SOURCE cr_event_tbl.sql
mysql> SOURCE cr_pet_tbl.sql
mysql> SOURCE load_pet_tbl.sql
mysql> SOURCE ins_puff_rec.sql
mysql> LOAD DATA LOCAL INFILE 'event.txt' INTO TABLE event;

ER図

menagerie.png

■classicmodels

クラシックカーのスケールモデルの小売店のDB

ソース

ダウンロード

curl -O https://www.mysqltutorial.org/wp-content/uploads/2023/10/mysqlsampledatabase.zip
unzip mysqlsampledatabase.zip 

リストア

リストア時にエラーが出る場合は、文字コードの設定を見直しましょう

ERROR 1366 (HY000): Incorrect string value: '\x85rhus' for column 'city' at row 43
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`classicmodels`.`orders`, CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customerNumber`) REFERENCES `customers` (`customerNumber`))
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`classicmodels`.`payments`, CONSTRAINT `payments_ibfk_1` FOREIGN KEY (`customerNumber`) REFERENCES `customers` (`customerNumber`))
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`classicmodels`.`orderdetails`, CONSTRAINT `orderdetails_ibfk_1` FOREIGN KEY (`orderNumber`) REFERENCES `orders` (`orderNumber`))

[解決例]
mysqlsampledatabase.sqlを編集

/* Switch to the classicmodels database */
USE classicmodels;
/* 私の場合、ダンプクエリに下記2行を追加することでリストア出来た*/
SET NAMES 'utf8mb4';
SET CHARACTER SET utf8mb4;

ER図

classicmodels.png

■northwind

Microsoft によって作成され、数十年にわたってさまざまなデータベース製品のチュートリアルの基礎として使用されてきたサンプル データベースです。Northwind データベースには、世界中の特殊食品を輸出入する「Northwind Traders」という架空の会社の販売データが含まれています。

ソース

リストア

mysql -u root -p
Enter password: **********

以下ページのクエリをコピペして実行

ER図

northwind.png

1
1
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
1
1