DB/MySQL

MySQL ์‹œ์ž‘ํ•˜๊ธฐ

osean 2020. 12. 20. 01:13

๋“ค์–ด๊ฐ€๊ธฐ ์ „์—

๊ต์œก์›์—์„œ Oracle์„ ์ด์šฉํ•ด์„œ ๋‘ ๊ฐœ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์—ˆ๋‹ค.
๋ฉฐ์น  ์ „, ์ข‹์€ ๊ธฐํšŒ๋กœ ์Šคํƒ€ํŠธ์—… ์ธํ„ด์œผ๋กœ ํ•จ๊ป˜ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๊ณ , ํšŒ์‚ฌ์—์„œ MySQL์„ ์‚ฌ์šฉํ•˜๊ธฐ์— ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ์ฒซ ์ถœ๊ทผํ•˜๋ฉด ๊ทธ๋ž˜๋„ ์กฐ๊ธˆ ๋” ์ˆ˜์›”ํ•˜๊ฒŒ ์ผ์„ ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„ ๊ธฐ๋ก์„ ๋‚จ๊ธฐ๋ ค๊ณ  ํ•œ๋‹ค.

Install MySQL

  • ๋งฅ์„ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋‹ˆ ์†์‰ฝ๊ฒŒ MySQL์„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋Š” Homeblew๋ฅผ ์ด์šฉํ•ด ์„ค์น˜ํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค. ์•„๋ž˜์˜ ๊ฒŒ์‹œ๊ธ€์„ ์ฐธ๊ณ ํ–ˆ๋‹ค.

 

[MySQL] MacOS ์—์„œ MySQL ์„ค์น˜

์ œ๋ชฉ ๊ทธ๋Œ€๋กœ MacOS ์—์„œ MySQL ์„ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ˆ ๋‹ค๋ฅธ ์šด์˜์ฒด์ œ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๋ถ„๋“ค์€ ๋‹ค๋ฅธ ๊ธ€์„ ์ฐธ๊ณ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. mysql ์„ ์„ค์น˜ํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค

ssungkang.tistory.com


Command

๋”๋ณด๊ธฐ
 

mysql.server start ์‹œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์™€ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

mysql.server start ์‹œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์™€ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์— ๊ด€ํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค.

velog.io

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

์„œ๋ฒ„์˜ ๋ฐฉํ™”๋ฒฝ์ด ํ’€๋ ค ์žˆ๋Š”์ง€ ํ™•์ธ์„ ํ•ด์•ผํ•œ๋‹ค. ใ…‡MySQL์€ ์„ค์น˜ ํ›„, ๋ฐ๋ชฌ(mysqld)์ด ๋Œ์•„๊ฐ€๊ณ , ํ•ด๋‹น ๋ฐ๋ชฌ์„ ํ†ตํ•ด MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ์ฆ‰, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฐ๋ชฌ์ด ์‹คํ–‰๋˜๊ณ  ์žˆ์–ด์•ผํ•œ๋‹ค.

  • brew services๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ์ ‘์† ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

// services ์ข…๋ฃŒ 
brew services stop mysql 

// services ์‹œ์ž‘ 
brew services start mysql 

// MySQL root ์‹คํ–‰ 
mysql -u -root -p
  • ๋จผ์ € ์•ž์„œ ๋งํ•œ ๊ฒƒ ์ฒ˜๋Ÿผ Oracle์„ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋‹ˆ MySQL์˜ ๊ถŒํ•œ ๋ถ€์—ฌ๋ผ๋˜์ง€ user ๋ฅผ ๋งŒ๋“ค๊ณ , ํ•ด๋‹น user ๊ฐ€ ์–ด๋–ค Database๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๋ช…๋ นํ•ด์ค˜์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ๋งŽ์ด ๋ง‰ํ˜”๋‹ค.

MySQL ์ ‘์†

mysql -u {user ์ด๋ฆ„} -p 

USER ์ƒ์„ฑ, ์‚ญ์ œ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ

  • USER ์ƒ์„ฑ์€ root์—์„œ ์ง„ํ–‰ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ„์˜ ๊ณผ์ •์„ root๋กœ ์ ‘์†ํ•ด์•ผ ํ•œ๋‹ค.
  • % ๋ฅผ host ์˜์—ญ์—์„œ ์ž…๋ ฅํ•˜์—ฌ USER๋ฅผ ์ƒ์„ฑํ•  ๊ฒฝ์šฐ, ์™ธ๋ถ€์—์„œ๋„ ํ•ด๋‹น USER์— ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ๋‚˜๋Š” USER NAME : spring, PW : spring์œผ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค.
// USER ์ƒ์„ฑํ•˜๊ธฐ
create user '์œ ์ €๋ช…'@'% ํ˜น์€ localhost' identified by 'ํŒจ์Šค์›Œ๋“œ';

// USER ์‚ญ์ œํ•˜๊ธฐ
delete from user where user = '์œ ์ €๋ช…';

// USER ์กฐํšŒ
select user, host from user;

// ์ƒ์„ฑ๋œ USER ๊ถŒํ•œ ๋ถ€์—ฌํ•˜๊ธฐ
grant all privileges on ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ช….* to '์œ ์ €๋ช…'@'ํ•ด๋‹น ์œ ์ €์˜ host';

Database ์ƒ์„ฑ ๋ฐ ์‚ญ์ œ, ์‚ฌ์šฉ ๋ช…๋ น, ์กฐํšŒ

  • MySQL์€ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€ ๋ช…๋ น์„ ๋‚ด๋ ค์ฃผ์–ด์•ผ ํ•œ๋‹ค.
// ์ƒ์„ฑ
create database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ช…;

// ์‚ญ์ œ
drop database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ช…;

// ์‚ฌ์šฉ ๋ช…๋ น
use ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ช…;

// ์กฐํšŒ
show databases;

๋ฒˆ๊ฒฝ๋œ ๋‚ด์šฉ ๋ฉ”๋ชจ๋ฆฌ์— ๋ฐ˜์˜

flush privileges;

์ฒดํฌํ•ด์•ผ ํ•  ๋ถ€๋ถ„๋“ค

  • DBeaver

    • DBeaver์—์„œ MySQL ์—ฐ๊ฒฐ ์‹œ, Driver properties → allowPublicKeyRetrieval์„ true๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  • URL ์„ค์ •

      jdbc:mysql://localhost:3306/DB์ด๋ฆ„?serverTimezone=Asia/Seoul&useSSL=false&characterEncoding=UTF-8
    • MySQL ํŠน์ • ๋ฒ„์ „ ์ดํ›„๋กœ๋Š” KST๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์•„ URL์— ์ง์ ‘ ์ง€์ •ํ•ด์ค˜์•ผ ํ•œ๋‹ค.
    • URL ์„ค์ • ์‹œ, ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ฃผ์–ด์•ผ ํ•œ๋‹ค.