前言:
在学习的时候,其实有一个正确的方法比起有一个正确的态度是更好的。就好比数据库的学习或者测试,如果我们要部署一个完整的可用的数据库,可能会需要耗费很多的时间和精力,而这些成本我们一般称之为沉没成本,因此,为了避免这些不必要的麻烦,选择一个快速的,准确的方法是非常有必要的哦。
那么,docker这样一种虚拟化技术就是非常的适合数据库的学习和测试啦。
接下来我将介绍从docker环境搭建开始直到一个完全可用的SQLserver服务器部署搭建完成的全过程。
先决条件:
(1)centos7服务器
(1)docker环境
(2)Navicat premium
一,
docker环境的搭建
docker的离线安装以及本地化配置_zsk_john的博客-CSDN博客
这里注意一点,一定要配置本地化。
二,
镜像下载地址:
Docker Hub 运行方法,示例什么的都有哦
官网好就好在连命令都给你提供了,docker pull命令为:
docker pull mcr.microsoft.com/mssql/server:2017-latest
启动SQLserver这个镜像:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=WhatIsUp_321" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
密码是WhatIsUp_321,SQLserver会检测密码的哦,因此,需要设置带字母数字特殊符号的密码
查看该容器得日志:
[root@slave1 openssh-8.6p1]# docker logs 83b2e SQL Server 2017 will run as non-root by default. This container is running as user root. To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216. 2022-09-01 08:06:59.32 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'. 2022-09-01 08:06:59.48 Server Did not find an existing master data file /var/opt/mssql/data/master.mdf, copying the missing default master and other system database files. If you have moved the database location, but not moved the database files, startup may fail. To repair: shutdown SQL Server, move the master database to configured location, and restart. 2022-09-01 08:06:59.49 Server Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'. 2022-09-01 08:06:59.51 Server Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'. 2022-09-01 08:06:59.65 Server Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'. 2022-09-01 08:06:59.79 Server Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'. 2022-09-01 08:07:00.05 Server Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'. 2022-09-01 08:07:00.13 Server Microsoft SQL Server 2017 (RTM-CU30) (KB5013756) - 14.0.3451.2 (X64) Jun 22 2022 18:20:15 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 18.04.6 LTS) 2022-09-01 08:07:00.14 Server UTC adjustment: 0:00 2022-09-01 08:07:00.15 Server (c) Microsoft Corporation. 。。。。。。。。。。。。。略略略 2022-09-01 08:07:05.36 spid11s The tempdb database has 1 data file(s). 2022-09-01 08:07:05.37 spid24s The Service Broker endpoint is in disabled or stopped state. 2022-09-01 08:07:05.37 spid24s The Database Mirroring endpoint is in disabled or stopped state. 2022-09-01 08:07:05.42 spid24s Service Broker manager has started. 2022-09-01 08:07:05.51 spid5s Recovery is complete. This is an informational message only. No user action is required. 2022-09-01 08:07:05.70 spid20s The default language (LCID 0) has been set for engine and full-text services.
OK了,这个镜像没有挂载volume。但,没关系,这不影响使用。如果想要挂载volume,容器内的挂载点路径是:/var/opt/mssql/data 剩下的就不用我说了吧,懂的都懂!!~~~~~~~~~~~
三,
打开Navicat premium开始连接SQLserver这个容器(linux服务器的IP地址是192.168.217.17,端口不需要指定,初始数据库也使用默认的master,用户名必须是sa,密码是WhatIsUp_321):
但,很可能会报错:
找到Navicat的安装目录,找到sqlncli_x64.msi,手动安装一哈这个SQLserver的客户端就可以啦。
再次连接应该就不会报错了。
总结:
docker十分的方便哦,数据库基本都不需要设置什么,像什么远程连接权限啊 什么的统统不用考虑,真正的开箱即用哦。