MySQL CLI (Frequently used)

์‚ฌ์šฉ์ž ๋ชฉ๋ก, ์ถ”๊ฐ€ , ์ œ๊ฑฐ ๊ถŒํ•œ ๋ถ€์—ฌ

๊ธฐ๋Šฅ

๋ช…๋ น์–ด

์‚ฌ์šฉ์˜ˆ

์„œ๋ฒ„ ๋กœ๊ทธ์ธ (MySQL์ ‘์†)

mysql -u [username] -p;

โ€ข mysql โ€“u root โ€“p; โ€ข password์ž…๋ ฅ

์‚ฌ์šฉ์ž ๋ชฉ๋ก ์กฐํšŒ

use mysql; select user, host from user;

โ€ขmysql๊ธฐ๋ณธ ์Šคํ‚ค๋งˆ mysql์•ˆ์— โ€ขmysql ๊ธฐ๋ณธ์Šคํ‚ค๋งˆ์ธ user table์—์„œ ํ™•์ธ๊ฐ€๋Šฅ.

์‚ฌ์šฉ์ž ์ถ”๊ฐ€

create user {username}@{ip} identified by '{password}';

โ€ขcreate user bit@localhost identified by 'bit'; โ€ขcreate user bit@123.456.% identified by 'bit';

์‚ฌ์šฉ์ž ์ œ๊ฑฐ

drop user {username}; drop user 'user'@'localhost';delete from user where user={username};

โ€ขdrop ์ถ”์ฒœ

๊ถŒํ•œ ํ™•์ธ

show grants for {username}@{ip};

โ€ข show grants for bit@localhost;

๊ถŒํ•œ ๋ถ€์—ฌ

grant {๊ถŒํ•œ} privileges on {์Šคํ‚ค๋งˆ}.{ํ…Œ์ด๋ธ”} to {username}@{ip};

โ€ข grant all privileges on *.* to bit@localhost;

๊ถŒํ•œ ์ œ๊ฑฐ

revoke {๊ถŒํ•œ} privileges on {์Šคํ‚ค๋งˆ}.{ํ…Œ์ด๋ธ”} from {username}@{ip};

โ€ข revoke all on bit.* from bit@localhost;

์‚ฌ์šฉ์ž ์ „ํ™˜

system mysql -u [์‚ฌ์šฉ์ž๋ช…] -p [password]

system mysql -u madang -p madang

DATABASE ์ƒ์„ฑ, ๋ชฉ๋ก, ๋ณด๊ธฐ

๊ธฐ๋Šฅ

๋ช…๋ น์–ด

์‚ฌ์šฉ ์˜ˆ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ

create database [database];

โ€ข database ์ƒ์„ฑ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ ํƒ

use [database];

โ€ข database ์„ ํƒ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ณด๊ธฐ

show databases;

โ€ข database ์–ด๋–ค ๊ฒŒ ์žˆ๋Š”์ง€ ๋ณด์—ฌ์คŒ

ํ…Œ์ด๋ธ” ๋ณด๊ธฐ

show tables;

โ€ข database ์— ์žˆ๋Š” ํ…Œ์ด๋ธ” ๋ณด์—ฌ์ค€๋‹ค.

Windows์—์„œ Database ๊ด€๋ฆฌ

  • windows์šฉ MySQL์€ windows ์žฌ ๋ถ€ํŒ…์‹œ ์ž๋™ ์‹คํ–‰ ๋œ๋‹ค. ์œˆ๋„์šฐ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌ

  • ์œˆ๋„์šฐ ๊ฒ€์ƒ‰ ์ฐฝ์—์„œ๋Š” services

  • ์‹คํ–‰์ฐฝ (window + R) ์—์„œ๋Š” services.msc ์ž…๋ ฅ.

  • ๋‚˜์˜ ๊ฒฝ์šฐ ํ•˜๋ฃจ ํ•˜๋ฃจ ์ข…์ผ ์“ฐ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ๋ถ€ํŒ… ์‹œ ์ˆ˜๋™์œผ๋กœ ์ผค ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ๋‹ค.

Last updated