MySQL Database

MySQL 은 λ‹€μŒ 두 개의 μš”μ†Œλ₯Ό ν¬ν•¨ν•œλ‹€.

  • MySQL Database Server
  • MySQL Workbench
MySQL Database Server

MySQL Database Server λŠ” data 듀을 μ‹€μ œλ‘œ μ €μž₯ν•˜λŠ” 곳이며, data 듀에 λŒ€ν•œ CRUD features 듀을 μ§€μ›ν•œλ‹€.

MySQL Workbench

MySQL Workbench λŠ” database 와 μƒν˜Έμž‘μš©ν•  수 μžˆλŠ” client GUI 이며, GUI λ₯Ό ν†΅ν•˜μ—¬ database schema 와 table 듀을 생성할 수 μžˆλ‹€. λ˜ν•œ SQL query 듀을 μ‹€ν–‰ν•˜μ—¬ data λ₯Ό κ°€μ Έμ˜¬ 수 μžˆλ‹€. database 에 λŒ€ν•˜μ—¬ data λ₯Ό insert, update, delete ν•  수 있으며, μ‚¬μš©μž 계정을 λ§Œλ“€κ³  κΆŒν•œμ„ μ„€μ •ν•˜κ±°λ‚˜ κ΄€λ¦¬ν•˜λŠ” λ“±μ˜ administrative ν•œ κΈ°λŠ₯을 μ‚¬μš©ν•  수 μžˆλ‹€. 이외에도 μ—¬λŸ¬κ°€μ§€ λ™μž‘μ„ μˆ˜ν–‰ν•  수 μžˆλ‹€.

Compatibility

MySQL Database Server 와 Workbench κ°„μ—λŠ” 버전 ν˜Έν™˜μ„±μ΄ μ‘΄μž¬ν•œλ‹€. ν…ŒμŠ€νŠΈμ— μ„±κ³΅ν•œ 버전 ν˜Έν™˜μ„±μ€ λ‹€μŒκ³Ό κ°™λ‹€.

Server - MySQL Community Server 8.0.41 Workbench - MySQL Workbench 8.0.41

Setting Up Database Table

Create New User

μš°μ„  Workbench μ—μ„œ Local instance 에 μ ‘μ†ν•œ λ’€, λ‹€μŒ SQL μ½”λ“œλ₯Ό μ‹€ν–‰ν•œλ‹€.

-- Drop user first if they exist
DROP USER if exists 'springstudent'@'localhost';
 
-- Now create user with prop privileges
CREATE USER 'springstudent'@'localhost' IDENTIFIED BY 'springstudent';
GRANT ALL PRIVILEGES ON * . * TO 'springstudent'@'localhost';

κ°„λ‹¨νžˆ μ‚΄νŽ΄λ³΄λ©΄, μš°μ„  localhost host λ₯Ό λŒ€μƒμœΌλ‘œ, springstudent λΌλŠ” user κ°€ μ‘΄μž¬ν•˜λ©΄ ν•΄λ‹Ή USER λ₯Ό μ‚­μ œν•œλ‹€.

κ·Έ μ΄ν›„μ—λŠ” μ‚¬μš©μž κ³„μ •μ˜ 이름을 springstudent, λΉ„λ°€λ²ˆν˜Έλ₯Ό springstudent 둜 μ„€μ •ν•˜μ—¬ μƒˆλ‘œμš΄ USER λ₯Ό μΆ”κ°€ν•œλ‹€.

λ§ˆμ§€λ§‰μœΌλ‘œ, localhost λ₯Ό λŒ€μƒμœΌλ‘œ, springstudent 계정에 λŒ€ν•˜μ—¬ *,*, 즉 λͺ¨λ“  λ°μ΄ν„°λ² μ΄μŠ€μ˜ λͺ¨λ“  ν…Œμ΄λΈ”μ— λŒ€ν•œ κΆŒν•œμ„ λΆ€μ—¬ν•œλ‹€.

이후 λͺ¨λ“  script λ₯Ό μ‹€ν–‰ν•˜κ³ , [Administration] > [Users and Privileges] > [User Accounts] μ—μ„œ μ‚΄νŽ΄λ³΄λ©΄ μ•„λž˜μ™€ 같이 springstudent 의 μ΄λ¦„μœΌλ‘œ μƒˆλ‘œμš΄ 계정이 μƒμ„±λœ 것을 λ³Ό 수 μžˆλ‹€.

Setup New Connection

이후 μœ„μ™€ 같이 springstudent 계정에 λŒ€ν•œ μƒˆλ‘œμš΄ Connection 을 μƒμ„±ν•œλ‹€. 이후 ν•΄λ‹Ή Connection 에 μ ‘μ†ν•œ 뒀에 λ‹€μŒ script λ₯Ό μ‹€ν–‰ν•˜μ—¬ student_tracker μ΄λΌλŠ” μ΄λ¦„μ˜ database λ₯Ό λ§Œλ“€κ³ , ν•΄λ‹Ή database μ•ˆμ—μ„œ student λΌλŠ” table 을 μƒμ„±ν•œλ‹€. table 의 κ΅¬μ‘°λŠ” λ‹€μŒ μ½”λ“œμ™€ 같이 κ΅¬μ„±ν•œλ‹€.

CREATE DATABASE  IF NOT EXISTS `student_tracker`;
USE `student_tracker`;
 
--
-- Table structure for table `student`
--
 
DROP TABLE IF EXISTS `student`;
 
CREATE TABLE `student` (
  `id` int NOT NULL AUTO_INCREMENT,
  `first_name`varchar(45) DEFAULT NULL,
  `last_name` varchar(45) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

ν•΄λ‹Ή script λ₯Ό μ‹€ν–‰ν•˜λ©΄ λ‹€μŒκ³Ό 같이 μ„±κ³΅μ μœΌλ‘œ database 와 table 이 μƒμ„±λœ 것을 λ³Ό 수 μžˆλ‹€.