본문 바로가기

IT/MySql

Mysql 테이블 조인 쿼리 SELECT a.col1, a.col2, a.col3, ... FROM tableA a LEFT JOIN tableB b on a.key = b.key SELECT a.col1, a.col2, a.col3, ... FROM tableA a RIGHTJOIN tableB b on a.key = b.key SELECT a.col1, a.col2, a.col3, ... FROM tableA a INNER JOIN tableB b on a.key = b.key SELECT a.col1, a.col2, a.col3, ... FROM tableA a LEFT JOIN tableB b on a.key = b.key WHERE b.key IS NULL SELECT a.col1, a.col2, a.col3, ... FR.. 더보기
Mysql UTF8 설정 * Mysql 5.7 기준 #vi /etc/my.cnf 아래 설정 삽입 [mysql] default-character-set = utf8 [mysqld] character-set-client-handshake=FALSE init_connect="SET collation_connection = utf8_general_ci" init_connect="SET NAMES utf8" character-set-server = utf8 collation-server = utf8_general_ci [client] default-character-set = utf8 더보기
Mysql 5.7 root 패스워드 os환경: centos 7 1. 설정변경 /etc/my.cnf skip-grant-tables 주석해제 2. mysql 시작 systemctl start mysqld 3. mysql 접속 mysql -u roo -p 패스워드 없이 그냥 엔터 4. user table 변경 >use mysql >select user, authentication_string from user; root 상황보기 >update user set authentication_string = "" where user='root'; > exit 5. mysql 중지 6. 설정변경 /etc/my.cnf skip-grant-tables 다시 주석처리 7. mysql 재시작 8. mysql -u root -p (패스워드 그냥 엔터) 9. 패.. 더보기
Mysql 테이블내 중목데이터 삭제 delete a from 테이블1 a, 테이블2 b where a.id < b.id and (a.칼럼1 = b.칼럼1 and a.칼럼2 = b.칼럼2 and a.칼럼3 = b.3 ......) 더보기
Mysql utf8 collation 문제 서버환경: CentOS7, mysql 5.7 mysql의경우 같은 utf8이라도 Collation에 있어서, utf8_unicode_ci와 utf8_general_ci의 중돌 문제가 있음. utf8_unicode_ci는 정확성이 좋으나 성능이 떨어지고, utf8_general_ci은 반대로 성능이 우수하다. default는 utf8_general_ci로 변경했으나 만약 문제가 있으면... > Alter Database DB명 Collate utf8_general_ci로 DB 초기 값을 설정을 변경한다. mysql의 설정 값을 보려면, > show variables like 'c%'; 더보기
Mysql 데이터 원격 복제(replication) master 서버의 mysql 데이터를 slave 서버로 원격 복제하고 싶은 경우가 있는데, 이때 활용할 수 있음. 다만, 오랜기간 실험한 것이 아니라 다소 불안정할 수 있는 점 양해 바랍니다^^ 서버환경: CentOS7, mysql 5.7 [Master 서버 설정] 1. 설정 # vi /etc/my.cnf 에 아래 내용 추가 log-bin=mysql-bin server-id=1 FLUSH TABLES WITH READ LOCK; change master to master_host ='123.123.123.123', master_port =3306, master_user ='유저아이디', master_password ='패스워드', master_log_file ='mysql-bin.000002', mas.. 더보기
MySql 2개 테이블 JOIN 업데이트 / 삭제 mysql 2개의 테이블을 특정 칼럼을 기준으로 연동하여 업데이트 또는 삭제하기 위한 쿼리 1. 테이블 업데이트 update TBL1 a inner join TBL2 b on a.col1 = b.col1 set a.col2 > 1 2. 테이블 삭제 [방법1] delete a from TBL1 a inner join TBL2 b on a.col1 = b.col1 where b.col2 = 'AAA' [방법2] delete from a using TBL1 a inner join TBL2 b on a.col1 = b.col1 where b.col2 = 'AAA' 더보기
MySql Fulltext 검색 MySql 5.7 이상은 InnoDB Fulltext Search에 대한 파서를 지원함. 1. mysql 시스템 변수 설정 검색시 문장 또는 단어를 잘라서 분석하기 위한 음절의 단위를 설정하기 위해 # vi /etc/my.cnf 아래 한 줄을 추가함. ngram_token_size=2 (토큰 값은 1~10, 기본 설정은 2) 2. Fulltaxt 인덱스 생성 - table 생성시 mysql> create table 테이블명 (id int auto-increment not null primary key, 칼럼1 varchar(50), 칼럼2 varchar(255), fulltext index ngram_idx(칼럼1) with parser ngram) engine=innodb character set ut.. 더보기