
MariaDB 설치
=> 10.6 버전을 초과하면 1년만 유지되는 단기 릴리스라고 하니 참고해서 하도록!
(업무 당시 Maria DB 언급이 나와 테스트 겸 작성해보려고 한다.) 추후 MySQL로 정해져서... 이 문서는 여기서 끝...
DB 생성
create database db명;
DB 확인
show databases;
DB 사용
use db명;
DB 삭제
drop database db명;
계정 생성
create user '아이디'@'%' identified by '비밀번호';
계정 권한 부여
grant all privileges on db명.* to '아이디'@'%';
새로고침
flush privileges;
계정 삭제
drop user '아이디'@'%';
컬럼 추가
alter table [테이블명] add [추가컬럼][속성];
ex) alter table table_name add add_column varchar(1) default null commnet 'xxx';
컬럼 삭제
alter table [테이블명] drop column [삭제컬럼];
ex) alter table table_name drop column del_column;
컬럼 변경
alter table [테이블명] change [변경전컬럼명][변경후컬럼명] [속성];
ex) alter table table_name change ori_column_name change_column_name varchar(1) not null commnet 'xxx';
컬럼 순서 변경
alter table [테이블명] modify [B컬럼][속성] after [A컬럼];
ex) alter table table_name modify b_column varchar(60) not null comment 'xxx' after a_column;
not null 추가
alter table [테이블명] modify [컬럼명][타입] [제약조건];
ex) alter table table_name modify column type not null;
기본키(primary key)
alter table [테이블명] add primary key(컬럼명);
ex) alter table table_name add primary key(column);
외래키(foreign key)
alter table [테이블명] add constraint [제약조건 이름] foreign key(컬럼명) reference [참조할 테이블] (참조할 테이블의 참조 컬럼);
ex) alter table table_name add constraint userid_fk foreign key(id) reference user(id);