文章目录
- MySQL示例数据库(MySQL Sample Databases) 之 world_x数据库
- 官方示例数据介绍
- world_x数据库
- world_x数据库安装
- world-db/world.sql的脚本内容
- 参考
MySQL示例数据库(MySQL Sample Databases) 之 world_x数据库
官方示例数据介绍
MySQL 官方提供了多个示例数据库,在MySQL的学习、开发和实践中具有非常重要的作用,能够帮助初学者更好地理解和应用MySQL的各种功能和特性。
官方示例数据具体列表如下:
1. employee data (large dataset, includes data and test/verification suite)
2. world database
3. world_x database
4. sakila database
5. airportdb database (large dataset, intended for MySQL on OCI and HeatWave)
6. menagerie database
这些数据库都可以通过如下官方网址进行下载和安装
https://dev.mysql.com/doc/index-other.html
world_x数据库
MySQL官方网站提供了另一个示例数据库 world_x,它是 world 数据库的扩展版本,包含了更多的数据和表。
world_x 数据库包含以下 4 个表:
-
city:
和 world 数据库中的一样,该表包含了世界各个城市的信息,包括所属国家、城市名称、人口等信息。 -
country:
该表包含了全球所有国家的信息,包括国家名称、首都、所属洲别等信息。 -
countrylanguage:
和 world 数据库中的一样,该表包含了全球各国语言的信息,包括所属国家、语言名称、官方语言等信息。 -
mysql.time_zone:
该表用于存储世界各地的时区信息,包括时区名称、UTC 偏差、所处洲别等信息。
该数据库可被用作MySQL基础练习和培训的教育工具,可利用它组织丰富的SQL查询和学习资源。官方网站还提供了该数据库下载和安装说明,方便用户快速掌握使用技巧。
world_x数据库安装
下载压缩包后就可以解压安装了。
解压:
ubuntu@mysql-vm:~$ unzip world_x-db.zip
Archive: world_x-db.zip
creating: world_x-db/
inflating: world_x-db/README.txt
inflating: world_x-db/world_x.sql
ubuntu@mysql-vm:~$
安装:
ubuntu@mysql-vm:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> source world_x-db/world_x.sql
查看数据
mysql> use world_x
Database changed
mysql> show tables;
+-------------------+
| Tables_in_world_x |
+-------------------+
| city |
| country |
| countryinfo |
| countrylanguage |
+-------------------+
4 rows in set (0.00 sec)
ubuntu@mysql-vm:~$ mysqlshow -uroot -prootroot -vv world_x
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: world_x
+-----------------+----------+------------+
| Tables | Columns | Total Rows |
+-----------------+----------+------------+
| city | 5 | 4079 |
| country | 4 | 239 |
| countryinfo | 3 | 239 |
| countrylanguage | 4 | 984 |
+-----------------+----------+------------+
4 rows in set.
world-db/world.sql的脚本内容
-- MySQL dump 10.13 Distrib 8.0.19, for osx10.14 (x86_64)
--
-- Host: 127.0.0.1 Database: world_x
-- ------------------------------------------------------
-- Server version 8.0.19-debug
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
SET @old_autocommit=@@autocommit;
--
-- Current Database: `world_x`
--
/*!40000 DROP DATABASE IF EXISTS `world_x`*/;
CREATE DATABASE `world_x` DEFAULT CHARACTER SET utf8mb4;
USE `world_x`;
--
-- Table structure for table `city`
--
DROP TABLE IF EXISTS `city`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `city` (
`ID` int NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Info` json DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `city`
--
-- ORDER BY: `ID`
set autocommit=0;
INSERT INTO `city` VALUES (1,'Kabul','AFG','Kabol','{\"Population\": 1780000}');
...
commit;
--
-- Table structure for table `country`
--
DROP TABLE IF EXISTS `country`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `country` (
`Code` char(3) NOT NULL DEFAULT '',
`Name` char(52) NOT NULL DEFAULT '',
`Capital` int DEFAULT NULL,
`Code2` char(2) NOT NULL DEFAULT '',
PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `country`
--
-- ORDER BY: `Code`
set autocommit=0;
INSERT INTO `country` VALUES ('ABW','Aruba',129,'AW');
...
commit;
--
-- Table structure for table `countryinfo`
--
DROP TABLE IF EXISTS `countryinfo`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `countryinfo` (
`doc` json DEFAULT NULL,
`_id` varbinary(32) GENERATED ALWAYS AS (json_unquote(json_extract(`doc`,_utf8mb4'$._id'))) STORED NOT NULL,
`_json_schema` json GENERATED ALWAYS AS (_utf8mb4'{"type":"object"}') VIRTUAL,
PRIMARY KEY (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `countryinfo`
--
-- ORDER BY: `_id`
set autocommit=0;
INSERT INTO `countryinfo` (`doc`) VALUES ('{\"GNP\": 828, \"_id\": \"00005de917d80000000000000000\", \"Code\": \"ABW\", \"Name\": \"Aruba\", \"IndepYear\": null, \"geography\": {\"Region\": \"Caribbean\", \"Continent\": \"North America\", \"SurfaceArea\": 193}, \"government\": {\"HeadOfState\": \"Beatrix\", \"GovernmentForm\": \"Nonmetropolitan Territory of The Netherlands\"}, \"demographics\": {\"Population\": 103000, \"LifeExpectancy\": 78.4000015258789}}');
...
INSERT INTO `countryinfo` (`doc`) VALUES ('{\"GNP\": 5951, \"_id\": \"00005de917d800000000000000ee\", \"Code\": \"ZWE\", \"Name\": \"Zimbabwe\", \"IndepYear\": 1980, \"geography\": {\"Region\": \"Eastern Africa\", \"Continent\": \"Africa\", \"SurfaceArea\": 390757}, \"government\": {\"HeadOfState\": \"Robert G. Mugabe\", \"GovernmentForm\": \"Republic\"}, \"demographics\": {\"Population\": 11669000, \"LifeExpectancy\": 37.79999923706055}}');
commit;
--
-- Table structure for table `countrylanguage`
--
DROP TABLE IF EXISTS `countrylanguage`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `countrylanguage` (
`CountryCode` char(3) NOT NULL DEFAULT '',
`Language` char(30) NOT NULL DEFAULT '',
`IsOfficial` enum('T','F') NOT NULL DEFAULT 'F',
`Percentage` decimal(4,1) NOT NULL DEFAULT '0.0',
PRIMARY KEY (`CountryCode`,`Language`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `countrylanguage_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `countrylanguage`
--
-- ORDER BY: `CountryCode`,`Language`
set autocommit=0;
INSERT INTO `countrylanguage` VALUES ('ABW','Dutch','T',5.3);
...
commit;
--
-- Dumping events for database 'world_x'
--
--
-- Dumping routines for database 'world_x'
--
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
SET autocommit=@old_autocommit;
-- Dump completed on 2020-01-22 9:58:16
参考
https://dev.mysql.com/doc/world-x-setup/en/