본문 바로가기

IT

PHP 배열 집합 연산 $arr1 = array('a', 'b', 'c', 'd'); $arr2 = array('c', 'd', 'e', 'f'); 1. 합집합 $arr = array_unique(array_merge($arr1, $arr2)); 2. 교집합 $arr = array_values(array_intersect($arr1, $arr2)); 3. 차집합 $arr = array_values(array_diff($arr1, $arr2)); 4. 대칭차집합 $arr = array_values(array_diff(array_merge($arr1, $arr2), array_intersect($arr1, $arr2))); 더보기
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' 더보기