본문 바로가기

DB17

[MariaDB] MariaDB ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2) 이전 눈물겹게 macbook을 한번 밀었다. 그래서 MariaDB를 재설치 해야하는 상황에 error가 났는데 참으로 힘겨웠다. ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2) 설치 후 sudo mariadb-secure-installation 를 하려할 때 이 에러가 났다. 원인은 server를 시작해주지 않아 생긴 일이었다. 평소 server를 자동으로 열게 설정해 놨기에 이 에러를 뵐 일이 없었다. brew services start mariadb로 서버를 시작하자 다음 에러가 났다. mariadb bootstrap failed: 5: input/output error try re-runnin.. 2022. 12. 20.
[MariaDB] 15. foreign key foreign key 외래키 테이블과 테이블을 연결할 때 쓴다. 만약 학생 정보 table과 시험 성적 table이 있다면, 기본적으로 회원 정보 table에 학생 정보가 있고 학번이 있을 것이다. 그런데 시험 성적 table에 data를 입력하려고 보니 없는 학번이 있으면 안 될 것이다. 이를 연결해주고, 시험 성적에서 학번이 어떤 학생인지를 알려주려 연결하는 것이 외래키이다. 이때 학생 정보 table이 참조 table이 되고 외래키로 지정되는 것이 시험 성적 table이다. 사용 참조 table의 column은 primary key여야 한다. foreign key는 참조값이나 null만 허용한다. 그 외에 없는 값은 안 된다. alter table 외래키table명 add [constraint co.. 2022. 12. 20.
[MariaDB] 14.primary key primary key 기본키 table당 한 개만 존재한다. unique + not null 설정 alter table table명 add constraint primary key(column명); alter table table명 modify column명 자료형 primary key; 제거 alter table table명 drop primary key; alter table table명 drop constraint column명; (not null은 제거 안 됨) ⇒ alter table table명 modify column명 자료형 null; → 만약 auto_increment가 걸려있다면 먼저 제거를 하고 그 다음 진행해야 한다. alter table table명 modify column명 자료.. 2022. 12. 20.
[MariaDB] 13.auto_increment id나 순번 같은 고유한 값을 자동으로 넣어주는 기능이 auto_increment이다. 설정 기존 조건을 지키면 된다. 조건 primary key만 가능 column이 int만 가능하다. 이미 설정된 column에 설정 alter table table명 modify column **int** auto_increment primary key ; table을 create할 때 설정 `create table table명 ( column명 int auto_increment primary key);` column을 id int로 만들고 auto_increment로 설정할 경우 따로 id 값을 넣지 않아도 자동으로 +1하여 들어간다. 그런데 만약 id를 3까지 만들고 2번을 지운다고 하면 auto_increment.. 2022. 12. 20.
[MariaDB] 12.union union table과 table의 date를 합친다. join이 칼럼을 연결했다면, union은 data를 연결 select column명, column명 from table명 union select column명, column명 from table명 union select column명, column명 from table명 만약 column이 같지 않아도 type만 맞으면 date가 합쳐짐 union all column끼리 붙을 때 중복되는 data가 있으면 한 가지만 나온다. 이를 모두 보기 위해서 union all를 쓴다. select column명, column명 from table명 union all select column명, column명 from table명 union all select.. 2022. 12. 20.
[MariaDB] 11. join join table과 table을 결합 select * from tableA, tableB select * from tableA, tableB where column = column 각각의 column을 매칭 시키려하는데 이때 두 column의 이름이 같게 되면 어떤 table의 column인지 모를 수도 있다. 아니면 두 column이 모두 tableA에도 있다고 치면 오류가 나온다. 그래서 select * from tableA, tableB where tableA.column = column 이라고 알려줘야한다. equal join select * from tableA join tableB on column = column; left outer join tableA(왼쪽)은 다 나오고 tableB에 .. 2022. 12. 20.