반응형
  • count(), count(distinct)
  • group_concat()
  • json_arrayagg() -> json array aggregate
  • json_objectagg() -> json object aggregate
  • sum(), max(), min()

 

select 
device_type, region
,group_concat(ric_code,'-', country_code) 
,JSON_ARRAYAGG(JSON_OBJECT('cntry',country_code, 'ric',ric_code))
,JSON_OBJECTAGG('cntry',country_code)
from tb_rc_ha_region group by device_type, region

반응형

'db' 카테고리의 다른 글

mysql 모든 table, key, index...etc 확인  (0) 2022.05.19
mysql change column error  (0) 2022.04.28
mysql timezone setting  (0) 2022.04.26
mysql 한글깨짐  (0) 2022.04.26
mysql console 접속  (0) 2022.04.26
반응형
  • check timezone
    • select @@global.time_zone, @@session.time_zone,@@system_time_zone;
    • select current_time;
  • modify timezone
    • sudo vim /etc/mysql/mysql.conf.d/mysqld.conf
    • 아래 줄 추가
      • default-time-zone="+00:00"
    • 그리고 재기동
      • sudo service mysql restart
반응형

'db' 카테고리의 다른 글

mysql change column error  (0) 2022.04.28
mysql aggregate function with group by  (0) 2022.04.27
mysql 한글깨짐  (0) 2022.04.26
mysql console 접속  (0) 2022.04.26
mysql date/time  (0) 2022.04.22
반응형

대부분 characterSet이 utf8로 설정되지 않아서 생긴 문제라고 함

  • 현재 characterSet 확인
    • show variables like 'c%'
    • mysql console접속 후 status 명령어 입력
  • mysql.ini 혹은 my.cnf 파일에 아래 내용 추가
    [client]
    default-character-set=utf8
    
    [mysql]
    default-character-set=utf8
    
    
    [mysqld]
    collation-server = utf8_unicode_ci
    init-connect='SET NAMES utf8'
    character-set-server = utf8

    • mysql.ini 혹은 my.cnf의 위치확인
      • show variables like '%dir' : 각종 경로를 알수 있음
      • 위 결과로 나오는 것 중에 basedir or datadir에 mysql.ini가 있다고 하는데 우분투에서는 없었음
      • 대신 /etc/mysql/my.cnf가 있어서 여기에 추가함
    • .ini는 윈도우에서 .cnf는 리눅스에서 쓰이는 설정파일인 것 같음,
      • 우분투에 설치된 mysql 버젼은 5.7.37-0ubuntu0.18.04.1였음
  • database와 table의 chatacterSet도 바꿔야 한다고 해서 바꿔줌
    • ALTER SCHEMA `cdp`  DEFAULT CHARACTER SET utf8  DEFAULT COLLATE utf8_bin;
    • workbench GUI에서도 가능
    • 테이블 characterSet도 일일히 바꿔야 한다는 얘기가 있었으나 하지 않음
  • 변경후 mysql 재시작하니 한글 정상노출됨
    • service mysql restart

 

반응형

'db' 카테고리의 다른 글

mysql aggregate function with group by  (0) 2022.04.27
mysql timezone setting  (0) 2022.04.26
mysql console 접속  (0) 2022.04.26
mysql date/time  (0) 2022.04.22
우분투 18.04 MongoDB 설치 및 구성  (0) 2022.04.18
반응형
  • local에서 접속
    • mysql -u [account] -p: 입력하면 비밀번호 입력하도록 유도됨
    • mysql -u [account]: 비밀번호 없이
  • 외부접속
    • mysql -h [ip] -p [port] -u [account] -p [databaseName]
  • 접속후 상태확인
    •  status
  • 접속종료
    • exit
반응형

'db' 카테고리의 다른 글

mysql timezone setting  (0) 2022.04.26
mysql 한글깨짐  (0) 2022.04.26
mysql date/time  (0) 2022.04.22
우분투 18.04 MongoDB 설치 및 구성  (0) 2022.04.18
mysql remote 접속허용  (0) 2022.04.14
반응형
  • DB timezone설정이 utc이면 current_timestamp=utc_timestamp이지만, 아니면 다름, 즉, current_timestamp = now() != utc_timestamp
    • select current_timestamp; -- 2022-04-22 16:06:16
      select current_time; -- 16:06:08
      select current_date; -- 2022-04-22
      select utc_timestamp; -- 2022-04-22 07:06:38
      select utc_time; -- 07:06:52
      select utc_date; -- 2022-04-22
      select now(); -- 2022-04-22 16:07:17
  • date, time, timestamp 차이
    • date: 날짜만 보여주고 날짜 정보까지만 가짐
    • time: 시간만 보여주지만 날짜 + 시간정보 모두 가짐
    • timestamp: 시간 full로 보여줌
    • 다음과 같이 function으로도 사용가능
select current_date, date(current_date), time(current_date), timestamp(current_date);
select current_time, date(current_time), time(current_time), timestamp(current_time);
select current_timestamp, date(current_timestamp), time(current_timestamp), timestamp(current_timestamp);
  • 날짜 더하기빼기: +1로 일단위,초단위 가능, 시간단위로 하려면 date_add 써야함
    • select utc_timestamp -- 2022-04-22 07:17:22
      union all
      select utc_timestamp + 1 -- 20220422071651 (+ 1 second)
      union all
      select utc_time + 1 -- 71651 (+ 1 second)
      union all
      select utc_date + 1 -- 20220423 (+ 1 day)
    • select current_timestamp() -- 2022-04-22 16:21:07
      union all
      select current_timestamp + 1 -- 20220422162108 (+ 1 second)
      union all
      select current_time + 1 -- 162108 (+ 1 second)
      union all
      select current_date + 1 -- 20220423 (+ 1 day)
    • select DATE_ADD(current_timestamp, interval 20 hour) -- 2022-04-23 00:00:00
      select DATE_ADD(current_date, interval 1 day)-- 2022-04-23
      select DATE_ADD(now(), interval 1 day)-- 2022-04-23 16:10:08
반응형

'db' 카테고리의 다른 글

mysql 한글깨짐  (0) 2022.04.26
mysql console 접속  (0) 2022.04.26
우분투 18.04 MongoDB 설치 및 구성  (0) 2022.04.18
mysql remote 접속허용  (0) 2022.04.14
mysql numeric type  (0) 2020.11.05
반응형
반응형

'db' 카테고리의 다른 글

mysql console 접속  (0) 2022.04.26
mysql date/time  (0) 2022.04.22
mysql remote 접속허용  (0) 2022.04.14
mysql numeric type  (0) 2020.11.05
mysql error - Invalid use of NULL value (이미 null들어간 column not null로 만들때 에러)  (0) 2020.05.25
반응형
  • 계정추가
    • select * from mysql.user로 현재 모든 user확인
    • create user 'root'@'%' identified by 'password'로 외부접속 가능한 계정을 추가
    • root@127.0.0.1만 있으면 localhost에서만 접속이 가능, root@%로 해서 외부접근 가능하도록 해줌
    • show grants for root@'%'로 권한확인
    • grant all privileges of *.* fo root@'%'로 권한추가해줌
  • mysql port 변경, 외부접속 허용
    • sudo vi /etc/mysql/mysql.conf.d/mysqld.conf로 설정파일 확인 (경로는 다를수 있음)
    • vi sudo로 안열면 readonly라서 안고쳐짐
    • 기본포트는 3306, port찾아서 변경가능
    • bind-address=127.0.0.1이거 있으면 외부접속 안됨, 주석처리해줌
    • 변경후 sudo service mysql restart로 재시작

 

반응형
반응형

mySQL Numeric Type 

최신 버젼 mysql에서는 bigint(20)으로 안나오고 bigint로 나온다

타입에 따라 자릿수는 정해지기 때문에 ()숫자는 의미가 없다고 한다

TINYINT(?)

SMALLINT(6)

MEDIUMINT(?)

INT(11)

BIGINT(20?)

 

반응형
반응형

alter table cdp.tb_rc_service_base modify biz_area varchar(500) NOT NULL;

실행시 Error Code: 1138. Invalid use of NULL value 발생.

not null column에 이미 null이 들어가있어 문제됨, null이 되지 않도록 update하거나

alter table cdp.tb_rc_service_base modify biz_area varchar(500) NOT NULL default ''; 수행하면됨 

반응형

'db' 카테고리의 다른 글

mysql remote 접속허용  (0) 2022.04.14
mysql numeric type  (0) 2020.11.05
mysql workbench timeout 설정 (Lost connection to MySQL server during query)  (0) 2020.05.25
mysql lock  (0) 2020.05.25
mysql data migration  (0) 2020.05.21
반응형

Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600으로 늘임

반응형

'db' 카테고리의 다른 글

mysql numeric type  (0) 2020.11.05
mysql error - Invalid use of NULL value (이미 null들어간 column not null로 만들때 에러)  (0) 2020.05.25
mysql lock  (0) 2020.05.25
mysql data migration  (0) 2020.05.21
oracle VS mysql  (0) 2020.02.26

+ Recent posts