블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.3
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

공지사항

최근에 올라온 글

  • 서버에서 caching_sha2_password 가 설정되면 connection string에  SslMode=none;ServerRsaPublicKeyFile=file.pem 옵션이 적용 가능함
  • 해당 file.pem 을 얻기 위해 아래 명령은 mysql 서버에서 실행 
SHOW STATUS LIKE 'Caching_sha2_password_rsa_public_key';
  • 결과중 아래 형식만 file.pem으로 저장 후 메일로 전달 (아래는 일부러 비정상 파일을 만들었음 키 정합성이 맞지 않음)
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnbV9QkygOGEzBsUBU2Ac
    Bnm/jBPs21lE7BxJRLudQx22s/0uXQAkG8e+O/sjGHLQlntUCYPMNQ4W3DNXLhXP
    v/W4KHmbYsVcWbMn3kZeCiuy7QTR4BUmDq2+QUYB1bk9twzToD7lNUny5cP+88Lf
    MjLF7bSYQCL3w+D53FKbnsT9uQSmS/+VhpNPWzrOZTJsiaSG/dDoCdx9fYhdUxWY
    bYo1UEA+nGAtEF7eYJrTPeAFlWlgDmzj5cyWO1CpEfLnazWl/RhuHRxb8gI/T+nL
    9qr0wLVZXt/ssEt74nolV5sKesX+QPQ8cJS3aWw4JDphqSMQaR2ZyAwX2nhYJlg8
    jwIDAQAB
    -----END PUBLIC KEY-----
  • 위 옵션은 .net 의 경우, Oracle의 MySQL.Data에서는 지원하지 않고 MySqlConnector 에서만 지원 가능함(23년 3월 13일 까지는 지원 안함)
  • MySQL.Data와 MySqlConnector에서 SslMode=none;AllowPublicKeyRetrieval=true 옵션을 사용해 접근할 수 있고, 이 옵션은 MITM 공격에 취약함 (중간자 공격)
  • 클라이언트에서 위 두 가지 방법중 아무것도 적용을 하지 않으면, 최초 접근이 실패하고 서버가 시작되고 한번이라도 성공한 커넥션이 있으면 접속 가능

https://mysqlconnector.net/connection-options/

 

MySQL Connection String for C# .NET Core Programs - MySqlConnector

MySqlConnector is a high-performance, asynchronous C# ADO.NET driver for MySQL Server, MariaDB, Amazon Aurora, Azure Database for MySQL, Google Cloud SQL for MySQL, Percona Server and more.

mysqlconnector.net

https://mysqlconnector.net/troubleshooting/retrieval-public-key/

 

Fix: Retrieval of the RSA public key is not enabled for insecure connections - MySqlConnector

Fixing 'Retrieval of the RSA public key is not enabled for insecure connections' error by using MySqlConnector and AllowPublicKeyRetrieval=True in the connection string.

mysqlconnector.net

sha256_password_auto_generate_rsa_keys

caching_sha2_password_auto_generate_rsa_keys

default_authentication_plugin = caching_sha2_password

 

Posted by 보미아빠
, |

recursive cte

카테고리 없음 / 2023. 3. 9. 06:41
-- recursive cte example

if object_id ('emp') is not null
drop table emp 
go

create table emp
(empId int
, empName nvarchar(100) 
, managerId int
) 
go

insert into emp (empId, empName, managerId)
select empId, empName, managerId 
from 
	( 
	  values 
	  (1 , 'name1', 3 )    -- level2
	, (2 , 'name2', 3 )    -- level2
	, (3 , 'name3', null ) -- level1
	, (4 , 'name4', 2 )    -- level3  
	, (5 , 'name5', 2 )    -- level3  
	, (6 , 'name6', 2 )    -- level3  
	, (7 , 'name7', 1 )    -- level3  
	, (8 , 'name8', 1 )    -- level3  
	, (9 , 'name9', 1 )    -- level3  
	, (10, 'name10', 9 )   -- level4
	) a (empId, empName, managerId)
go

; with empCte
as 
(
-- recursive anchor query
select empId, empName, managerId, 1 memLevel
from emp 
where empId = 3

union all 

-- recursive target query 
select b.empId, b.empName, b.managerId, a.memLevel + 1 memLevel
from empCte a -- anchor 
	join emp b 
	on b.managerId = a.empId 
)
-- cooking 
select a.empId, a.empName, isnull(b.empName, 'no parent') managerName, a.memLevel
from empCte a
	left join emp b
	on b.empId = a.managerId
order by 1

 

Posted by 보미아빠
, |
if object_id ('temp') is not null
drop table temp 
go

create table temp
(id varchar(20)
, time time 
, product varchar(100)
) 
go

insert into temp (id, time, product)
select id, time, product 
from 
	( 
	  values 
	  ('A', '08:10', 'pizza' )
	, ('A', '09:55', 'noodle' )
	, ('B', '12:30', 'pizza' )
	) a (id, time, product)
go

-- Consider the pros and cons of both queries.
-- 1 
; with a
as 
(
select row_number() over (partition by id order by time asc) rn , * 
from temp 
)
select *
from a 
where rn = 1 

-- 2
select b.*
from 
	(
	select distinct id 
	from temp a
	) a
	cross apply 
	(
	select top 1 * 
	from temp 
	where id = a.id
	order by time 
	) b
Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함