Lloyd Banks
Lloyd Banks

Reputation: 36679

Difference Between Schema / Database in MySQL

Is there a difference between a schema and a database in MySQL? In SQL Server, a database is a higher level container in relation to a schema.

I read that Create Schema and Create Database do essentially the same thing in MySQL, which leads me to believe that schemas and databases are different words for the same objects.

Upvotes: 396

Views: 287515

Answers (10)

khoa junior
khoa junior

Reputation: 29

not like Postgres, SQL server schema is set of database have same thing but in mysql schema and database it is the same MySQL does not support the concept of schema. In MySQL, schema and schemas are synonyms for database and databases.

When a user connects to MySQL, they don't connect to a specific database. Instead, they can access any table they have permissions for

Upvotes: 0

高欣平
高欣平

Reputation: 292

Just add some more info:

MongoDB also distinguish schema from database.

schema represent the tables, which means the structure of database.

Upvotes: 1

Md. Sahaib Mridha
Md. Sahaib Mridha

Reputation: 61

Simply if you are thinking or discussing about Mysql. Then take a simple answer

"SCHEMA & DATABASE are exactly the same thing, just a synthetic sugar in mysql."

Upvotes: 5

Riz
Riz

Reputation: 111

in MySQL schema is synonym of database. Its quite confusing for beginner people who jump to MySQL and very first day find the word schema, so guys nothing to worry as both are same.

When you are starting MySQL for the first time you need to create a database (like any other database system) to work with so you can CREATE SCHEMA which is nothing but CREATE DATABASE

In some other database system schema represents a part of database or a collection of Tables, and collection of schema is a database.

Upvotes: 11

Jean-Michel P.
Jean-Michel P.

Reputation: 227

PostgreSQL supports schemas, which is a subset of a database: https://www.postgresql.org/docs/current/static/ddl-schemas.html

A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database they are connected to, if they have privileges to do so.

Schemas are analogous to directories at the operating system level, except that schemas cannot be nested.

In my humble opinion, MySQL is not a reference database. You should never quote MySQL for an explanation. MySQL implements non-standard SQL and sometimes claims features that it does not support. For example, in MySQL, CREATE schema will only create a DATABASE. It is truely misleading users.

This kind of vocabulary is called "MySQLism" by DBAs.

Upvotes: 21

user2631022
user2631022

Reputation: 1021

Depends on the database server. MySQL doesn't care, its basically the same thing.

Oracle, DB2, and other enterprise level database solutions make a distinction. Usually a schema is a collection of tables and a Database is a collection of schemas.

Upvotes: 101

EliD
EliD

Reputation: 11

Microsoft SQL Server for instance, Schemas refer to a single user and is another level of a container in the order of indicating the server, database, schema, tables, and objects.

For example, when you are intending to update dbo.table_a and the syntax isn't full qualified such as UPDATE table.a the DBMS can't decide to use the intended table. Essentially by default the DBMS will utilize myuser.table_a

Upvotes: 1

Akash KC
Akash KC

Reputation: 16310

Refering to MySql documentation,

CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE as of MySQL 5.0.2.

Upvotes: 23

eggyal
eggyal

Reputation: 125985

As defined in the MySQL Glossary:

In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE.

Some other database products draw a distinction. For example, in the Oracle Database product, a schema represents only a part of a database: the tables and other objects owned by a single user.

Upvotes: 466

Mike Brant
Mike Brant

Reputation: 71422

Yes, people use these terms interchangeably with regard to MySQL. Though oftentimes you will hear people inappropriately refer to the entire database server as the database.

Upvotes: 6

Related Questions