데이터베이스를 생성하는 방법 MySQL (창조하다 MySQL 테이블)
⚡ 스마트 요약
데이터베이스 생성 MySQL follows two proven paths: executing a CREATE DATABASE statement, or generating physical schemas from an ER model through MySQL Workbench forward engineering. Both approaches produce identical, production-ready tables.

데이터베이스를 생성하는 단계 MySQL
A database in MySQL is a named container for tables, views, and related objects. You can create one in two ways:
1) 간단한 SQL 쿼리를 실행하여
2) 포워드 엔지니어링을 활용하여 MySQL 워크 벤치
As SQL 초보자, 먼저 쿼리 방법을 살펴보겠습니다.
데이터베이스를 생성하는 방법 MySQL
데이터베이스를 생성하는 방법은 다음과 같습니다. MySQL:
CREATE DATABASE는 데이터베이스를 생성하는 데 사용되는 SQL 명령입니다. MySQL.
Imagine you need to create a database with the name “movies”. You can create a database in MySQL by executing the following SQL command.
CREATE DATABASE movies;
Note: You can also use the command CREATE SCHEMA instead of CREATE DATABASE.
The statement works only once. Running it again throws an error, so let’s improve the query with more parameters.
존재하지 않는 경우
하나의 MySQL server can hold many databases. When several people share that server, you may try to create a database with the name of an existing one.
존재하지 않는 경우 instructs the MySQL server to check for a database with the same name before creating it. The database is created only if the name is free; without this clause, MySQL 오류가 발생합니다.
CREATE DATABASE IF NOT EXISTS movies;
Once the database name is safe, the next decision is how MySQL should store and compare the text inside it.
데이터 정렬 및 문자 집합
A 문자 집합 decides which characters a column can store, while a 대조 의 집합이다 rules used in comparison and sorting. Both can be defined at four levels: server, database, table, and column.
The collation you choose depends on the character set. For instance, the latin1 character set uses the latin1_swedish_ci collation, which is the Swedish case-insensitive order.
CREATE DATABASE IF NOT EXISTS movies CHARACTER SET latin1 COLLATE latin1_swedish_ci;
For local languages such as Arabic or Chinese, select the Unicode utf8mb4 character set, which stores every Unicode character, including emoji. In MySQL 8.0, utf8mb4 is the default character set and utf8mb4_0900_ai_ci the default collation.
CREATE DATABASE IF NOT EXISTS movies CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
모든 데이터 정렬 및 문자 집합 목록을 찾을 수 있습니다. 여기에서 확인하세요.
You can see the list of existing databases by running the following SQL command.
SHOW DATABASES;
With the database in place, you can now add the tables that will actually hold the records.
테이블을 만드는 방법 MySQL
The CREATE TABLE command is used to create tables in a database.
As the diagram shows, every table belongs to one database. Tables are created with the 테이블 만들기 statement, which has the following syntax.
CREATE TABLE [IF NOT EXISTS] `TableName` (`fieldname` dataType [optional parameters]) ENGINE = storage Engine;
여기를 클릭하십시오.
- “CREATE TABLE” is responsible for the creation of the table in the database.
- “[IF NOT EXISTS]” is optional and only creates the table if no matching table name is found.
- “`fieldName`” is the name of the field, and “data Type” defines the nature of the data stored in it.
- “[optional parameters]” is extra information about a field, such as “AUTO_INCREMENT” or NOT NULL.
- “storage Engine” manages the table, normally InnoDB, which supports transactions and foreign keys.
MySQL 테이블 생성 예
아래는 MySQL example to create a table in a database:
CREATE TABLE IF NOT EXISTS `MyFlixDB`.`Members` ( `membership_number` INT AUTO_INCREMENT , `full_names` VARCHAR(150) NOT NULL , `gender` VARCHAR(6) , `date_of_birth` DATE , `physical_address` VARCHAR(255) , `postal_address` VARCHAR(255) , `contact_number` VARCHAR(75) , `email` VARCHAR(255) , PRIMARY KEY (`membership_number`) ) ENGINE = InnoDB;
참고 : 정확한 MySQL 키워드는 AUTO_INCREMENT with an underscore. AUTOINCREMENT 속해있다 SQLite and raises a syntax error in MySQL.
Every column carries a data type, so choose carefully: neither underestimate nor overestimate the range of data you expect.
MySQL 데이터 타입
Data types define the nature of the data that can be stored in a particular column of a table.
MySQL 이 3 main categories of data types, namely:
- 숫자
- 본문
- 날짜 시간
숫자 형 데이터 타입
Numeric data types are used to store numeric values. It is very important to make sure the range of your data is between the lower and upper boundaries of the numeric data type you pick.
| TINYINT( ) | -128 ~ 127 일반 0~255 서명되지 않음. |
| SMALLINT( ) | -32768 ~ 32767 일반 0~65535 서명되지 않음. |
| 보통( ) | -8388608 ~ 8388607 일반 0~16777215 서명되지 않음. |
| 지능( ) | -2147483648 ~ 2147483647 일반 0~4294967295 서명되지 않음. |
| 빅트( ) | -9223372036854775808 ~ 9223372036854775807 일반 0~18446744073709551615 서명되지 않음. |
| 흙손 | 부동 소수점이 있는 작은 대략적인 숫자입니다. |
| 더블( , ) | 부동 소수점이 있는 큰 숫자입니다. |
| 십진수( , ) | A DOUBLE stored as a string, allowing for a fixed decimal point. Choice for storing currency values. |
텍스트 데이터 유형
As the data type category name implies, these are used to store text values. Always make sure the length of your textual data does not exceed the maximum length of the column.
| 문자( ) | 0~255자 길이의 고정 섹션입니다. |
| VARCHAR( ) | 0~255자 길이의 변수 섹션입니다. |
| 타이니텍스트 | 최대 길이가 255자인 문자열입니다. |
| TEXT | 최대 길이가 65535자인 문자열입니다. |
| 얼룩 | 최대 길이가 65535자인 문자열입니다. |
| 중간 텍스트 | 최대 길이가 16777215자인 문자열입니다. |
| 미디엄블롭 | 최대 길이가 16777215자인 문자열입니다. |
| 긴 텍스트 | 최대 길이가 4294967295자인 문자열입니다. |
| 롱블롭 | 최대 길이가 4294967295자인 문자열입니다. |
Date and Time Data Types
Date and time data types store calendar and clock values in a fixed format, which keeps sorting and comparison reliable.
| 날짜 | YYYY-MM-DD |
| 날짜 시간 | YYYY-MM-DD HH : MM : SS |
| 타임 스탬프 | YYYYMMDDHHMMSS |
| TIME | HH : MM : SS |
기타 데이터 유형
Apart from the above, there are some other data types in MySQL.
| 열거형 | To store a text value chosen from a list of predefined text values |
| SET를 | 이는 미리 정의된 텍스트 값 목록에서 선택한 텍스트 값을 저장하는 데에도 사용됩니다. 여러 값을 가질 수 있습니다. |
| BOOL | 부울 값을 저장하는 데 사용되는 TINYINT(1)의 동의어 |
| BINARY | Similar to CHAR; the difference is that texts are stored in binary format. |
| 바르바이너리 | Similar to VARCHAR; the difference is that texts are stored in binary format. |
Now let’s see a query for creating a table which uses all the data types. Study it and identify how each data type is defined in the below create table MySQL 예.
CREATE TABLE `all_data_types` ( `varchar` VARCHAR( 20 ) , `tinyint` TINYINT , `text` TEXT , `date` DATE , `smallint` SMALLINT , `mediumint` MEDIUMINT , `int` INT , `bigint` BIGINT , `float` FLOAT( 10, 2 ) , `double` DOUBLE , `decimal` DECIMAL( 10, 2 ) , `datetime` DATETIME , `timestamp` TIMESTAMP , `time` TIME , `year` YEAR , `char` CHAR( 10 ) , `tinyblob` TINYBLOB , `tinytext` TINYTEXT , `blob` BLOB , `mediumblob` MEDIUMBLOB , `mediumtext` MEDIUMTEXT , `longblob` LONGBLOB , `longtext` LONGTEXT , `enum` ENUM( '1', '2', '3' ) , `set` SET( '1', '2', '3' ) , `bool` BOOL , `binary` BINARY( 20 ) , `varbinary` VARBINARY( 20 ) ) ENGINE = MYISAM;
최고의 Practices for Creating a MySQL 데이터베이스
A few conventions keep your scripts readable:
- Use upper case letters for SQL keywords, i.e. “DROP SCHEMA IF EXISTS `MyFlixDB`;”
- End all your SQL commands using semicolons.
- Avoid using spaces in schema, table, and field names. Use underscores instead to separate schema, table, or field names.
- Prefer InnoDB over MyISAM for new tables, because InnoDB supports transactions, row-level locking, and foreign keys.
The query method is complete. The second route reaches the same database from a visual model instead of hand-written SQL.
어떻게 작성 방법 MySQL Workbench ER Diagram Forward Engineering
MySQL 워크 벤치 포워드 엔지니어링을 지원하는 유틸리티가 있습니다. 포워드 엔지니어링 is the technical term that describes the process of translating a logical model into a physical implementation automatically.
우리는 만들었습니다 ER 다이어그램 우리의 응급실 모델링 lesson. We will now use that ER model to generate the SQL scripts that will create our database.
MyFlix ER 모델에서 MyFlix 데이터베이스 생성
Step 1) Open the ER model of the MyFlix database 이전에 생성한 것입니다.
Step 2) 포워드 엔지니어 선정
Click on the Database menu and select Forward Engineer.
Step 3) Connection options
The next window allows you to connect to an instance of MySQL server. Click on the stored connection drop-down list and select local host. Click Execute.
Step 4) Select the options shown below
Select the options shown below in the wizard that appears. Click Next.
Step 5) Keep the selections default and click Next
The next screen shows the summary of objects in our EER diagram. Our MyFlix DB has 5 tables. Keep the selections default and click Next.
단계 6) RevSQL 스크립트를 봐요
The window below previews the SQL script that creates our database. Save the script to a *.sql file or copy it to the clipboard, then click Next.
Step 7) Commit progress
The window below appears once the database is created on the selected MySQL server instance. The tables from the ER model now exist physically on the server.
The database along with dummy data is attached. We will use this DB in the lessons that follow. Simply import it in MySQL Workbench to get started.







.png)