본문 바로가기
DB/SQL Server

docker / SQLSERVER / MSSQL / 데이터베이스생성 / 계정생성 / 권한부여

by 하하IT 2024. 2. 29.

1. docker CONTAINER ID 확인 

user@PC:/$ docker ps
CONTAINER ID   IMAGE                                        COMMAND                  CREATED         STATUS         PORTS                                                             NAMES
7c226918297a   mcr.microsoft.com/mssql/server:2019-latest   "/opt/mssql/bin/perm…"   9 minutes ago   Up 9 minutes   0.0.0.0:11433->1433/tcp, :::11433->1433/tcp                       sql-server-container
user@PC:/$



2. sqlcmd 실행 
2.1 docker 내부 Container console 실행 

user@PC:/$ docker exec -it 7c226918297a /opt/mssql-tools/bin/sqlcmd -S localhost -d master -U sa -P 'YourPassword123!'

 


2.2 docker 내부 Container console 실행 

user@PC:/$ docker exec -it 7c226918297a /bin/bash
mssql@7c226918297a:/$
mssql@7c226918297a:/$
mssql@bc9586e4629e:/$ /opt/mssql-tools/bin/sqlcmd -S localhost  -U sa -P 'YourPassword123!'
1>
2>




3. 데이터베이스생성 / 계정생성 / 권한부여

CREATE DATABASE TEST2; --데이터베이스생성
GO   --명령을 사용하여 명령을 실행 및 트랜잭션종료

CREATE LOGIN TEST2 WITH PASSWORD = 'TEST123!@#';
USE TEST2;
CREATE USER TEST2 FOR LOGIN TEST2;
EXEC sp_addrolemember 'db_owner', 'TEST2';

GO