在docker环境中快速使用SQL Server各个版本的数据库(2017、2019、2022)

2023-09-08 16:23:23 浏览数 (1)

SQL Server官方镜像

请参考: https://hub.docker.com/_/microsoft-mssql-server

参考:https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-docker?view=sql-server-2017&pivots=cs1-bash

代码语言:javascript复制
docker search mssql
docker pull mcr.microsoft.com/mssql/server:2017-latest
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker pull mcr.microsoft.com/mssql/server:2022-latest

-- 2017
docker rm -f mssql2017
docker run -d --name mssql2017 --hostname  mssql2017 
-p 1401:1433  
-e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lhr@zr123" 
-e "TZ=Asia/Shanghai" 
-e "MSSQL_PID=Enterprise" 
-e "MSSQL_LCID=2052" 
-e "MSSQL_COLLATION=Chinese_PRC_CI_AS" 
-e "MSSQL_AGENT_ENABLED=true" 
mcr.microsoft.com/mssql/server:2017-latest

docker exec -it mssql2017 bash
/opt/mssql-tools/bin/sqlcmd  -S localhost -U sa -P "lhr@zr123"
sqlcmd -S 192.168.8.8,1401 -U SA -P "lhr@zr123"


-- 2019
docker rm -f mssql2019
docker run -d --name mssql2019  --hostname  mssql2019 
-p 1402:1433  
-e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=lhr@zr123" 
-e "TZ=Asia/Shanghai" 
-e "MSSQL_PID=Enterprise" 
-e "MSSQL_LCID=2052" 
-e "MSSQL_COLLATION=Chinese_PRC_CI_AS" 
-e "MSSQL_AGENT_ENABLED=true" 
mcr.microsoft.com/mssql/server:2019-latest

docker exec -it mssql2019 bash
/opt/mssql-tools/bin/sqlcmd  -S localhost -U sa -P "lhr@zr123"
sqlcmd -S 192.168.8.8,1402 -U SA -P "lhr@zr123"


-- 2022
docker rm -f mssql2022
docker run -d --name mssql2022 --hostname  mssql2022 
-p 1403:1433  
-e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=lhr@zr123" 
-e "TZ=Asia/Shanghai" 
-e "MSSQL_PID=Enterprise" 
-e "MSSQL_LCID=2052" 
-e "MSSQL_COLLATION=Chinese_PRC_CI_AS" 
-e "MSSQL_AGENT_ENABLED=true" 
mcr.microsoft.com/mssql/server:2022-latest


docker exec -it mssql2022 bash
/opt/mssql-tools/bin/sqlcmd  -S localhost -U sa -P "lhr@zr123"
sqlcmd -S 192.168.8.8,1433 -U SA -P "lhr@zr123"

SELECT Name from sys.Databases
go

SELECT @@VERSION
SELECT SERVERPROPERTY('Edition')
go


-- 修改sa密码
USE [master]
GO
ALTER LOGIN [sa] WITH CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
ALTER LOGIN [sa] WITH PASSWORD=N'lhr'
GO

-- 修改内存

SELECT * FROM sys.configurations d
where d.name like '%max server memory (MB)%'  
ORDER BY name ;
GO



sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'max server memory (MB)', 1024;
GO
RECONFIGURE WITH OVERRIDE;
GO


-- 远程登录
sqlcmd -S 192.168.8.8,1403 -U sa -P lhr
sqlcmd -S 192.168.8.8,1403 -d master -h -1 -U sa -P lhr -W -Q "set nocount on;SELECT name FROM master..sysdatabases"


-- linux客户端
curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
yum install -y mssql-tools unixODBC-devel mssql-cli

echo "export PATH=/opt/mssql-tools/bin:$PATH" >> /root/.bashrc
source /root/.bashrc

-- 建库
create database lhrdb COLLATE Chinese_PRC_BIN;

麦老师自制镜像

代码语言:javascript复制
nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/mssql2019:2.0  &
nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/mssql2017:2.0  &
nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/mssql2022:2.0  &


docker rm -f lhrmssql2017
docker run -d --name lhrmssql2017 -h lhrmssql2017 
  -p 1437:1433 -p 217:22 
  -v /sys/fs/cgroup:/sys/fs/cgroup 
  --privileged=true lhrbest/mssql2017:2.0 
  /usr/sbin/init


docker rm -f lhrmssql2019
docker run -d --name lhrmssql2019 -h lhrmssql2019 
  -p 1439:1433 -p 219:22 
  -v /sys/fs/cgroup:/sys/fs/cgroup 
  --privileged=true lhrbest/mssql2019:2.0 
  /usr/sbin/init  



docker rm -f lhrmssql2022
docker run -d --name lhrmssql2022 -h lhrmssql2022 
  -p 14322:1433 -p 222:22 
  -v /sys/fs/cgroup:/sys/fs/cgroup 
  --privileged=true lhrbest/mssql2022:2.0 
  /usr/sbin/init

0 人点赞