본문 바로가기
macOS

[mac M1] brew를 활용한 간단한 MySQL 설치 및 간단한 명령어

by pilgyeong 2023. 1. 10.

MySQL

 

brew를 통한 MySQL 설치하기

 

brew install 

# 먼저 brew를 update
brew update

# install
brew install mysql

 

brew를 통한 mysql server 실행

# start
brew services start mysql

# stop
brew services stop mysql

brew services start mysql

 

local 환경에서 연습하는 것이기 때문에 root 비번을 따로 설정하지 않았음. 만약 하고 싶으면, 아래 명령어를 통해 password 설정

mysql_secure_installation

 

mysql 접속(실행)

# pw 없는 경우
mysql -uroot

# pw 있는 경우 (한 번에 명령)
mysql -uroot -p{설정한 비번}

# pw 있는 경우 (비번은 따로 치기)
mysql -uroot -p

 

 


 

 

커맨드에서 간단한 명령어

 

schema 조회

# mysql은 ;를 붙여줌
show schemas;

 

 

schema 생성

# DB명령어에서 unique한 schema 또는 table을 지칭할 때, '1' 왼쪽(esc 아래)에 있는 빽쿼트(뒤로 꺽쇠)
create schema `test-schema`;

 

 

use schema

# 내가 사용할 schema를 세팅
use test-schema;

 

table 생성

# create 명령어
create table `table1` (`id` INT not null, `name` varchar(255), PRIMARY KEY(`id`));

 

 

describe 명령

# 해당 table의 전체적인 정보
describe table `table1`;

# 해당 table의 column에 대한 정보
describe `table1`;