先上结论:MySQL中,可以把Schema当作Database,区别在于 Schema是软件抽象层面,Database是数据存储的物理层面,他们背后都是同一套东西(数据,触发器,锁 .....)。
MySQL官方文档有介绍:
Conceptually, a schema is a set of interrelated database objects, such as tables, table columns, data types of the columns, indexes, foreign keys, and so on. These objects are connected through SQL syntax, because the columns make up the tables, the foreign keys refer to tables and columns, and so on. Ideally, they are also connected logically, working together as part of a unified application or flexible framework. For example, theINFORMATION_SCHEMA and performance_schema databases use “schema” in their names to emphasize the close relationships between the tables and columns they contain.
In MySQL, physically, aschema is synonymous with adatabase. You can substitute the keyword
SCHEMA
instead ofDATABASE
in MySQL SQL syntax, for example usingCREATE SCHEMA
instead ofCREATE DATABASE
.Some other database products draw a distinction. For example, in the Oracle Database product, aschema represents only a part of a database: the tables and other objects owned by a single user.
从文中的红字可以看到,在MySQL的 SQL语句中甚至可以直接使用 schema 来 代替 database