Creating a Schema (Database)
Operation confirmation environment
- MySQL
-
- MySQL 8.4
- MySQL Workbench
-
- 8.0
- Windows
-
- Windows Server 2022
Required environment
- MySQL
-
- MySQL 8.4 or later
- Previous versions are also acceptable
- MySQL Workbench
-
- 8.0 or later
- Windows
-
- Windows 11
- Windows 10
- Windows Server
-
- Windows Server 2022
- Windows Server 2019
- Windows Server 2016
precondition
- Make sure you can connect to your MySQL database
- If you want to use Workbench, Workbench must be installed
- Connect to the database with permissions to create schemas
About Schema
A schema in MySQL is equivalent to a "one-size-fits-all database" for other databases. Basically, this way of thinking is fine, but there are some parts that are slightly different, so please check the official website or other sites for details. This is an explanation of the procedure for creating a schema, so I will not explain the schema itself.
Create a schema in Workbench
Select MySQL > MySQL Workbench from the Start menu.
Connect to the database.
The "sys" schema that exists from the beginning is for the system, so we will create a new one separately. Select the Schemas tab from the Nevigator pane on the left, right-click on the blank space, and select Create Schema.
Enter a name. By default, it will be converted to lowercase letters, so it is better to enter in lowercase letters from the beginning. Change the other values if necessary. Once you have entered it, click the "Apply" button in the bottom right corner.
You will see the SQL being executed, click the "Apply" button.
If successful, it will be displayed as shown in the image below, so click the "Finish" button.
You can see that the schema you entered in the Schema tab has been added.
Creating a Schema in a Command
There are several ways to run commands, but this time we'll use the command-line tool in an environment with MySQL installed.
Launch MySQL > MySQL 8.4 Command Line Client from the Start menu. There is also a Unicode version, but if you only use half-width alphanumeric characters, there is no substitute for either.
Enter your MySQL administrator password.
SQL can be executed, so enter the following: Please set the schema name as you like. Since SQL can enter multiple lines, a semicolon is required at the end to make the end of the SQL known. Once you've typed, press Enter.
CREATE DATABASE `test_schema2`;
If you can run it without errors, you're done.
You can see the list of schemas that have been created by running the following SQL:
SHOW DATABASES;