您的位置:新葡亰496net > 网络数据库 > 新葡亰496net数据水库蓄水容量器化,CentOS7脱机安

新葡亰496net数据水库蓄水容量器化,CentOS7脱机安

发布时间:2019-09-15 20:18编辑:网络数据库浏览(76)

    1. 背景

    SQL Server on Linux也发布一段时间了,官方上支持Red Hat, SUSE, Ubuntu。手上没有以上Linux版本,选用了与Red Hat最接近的CentOS7.4来进行安装和测试。

    SQL Server on Linux也发布一段时间了,官方上支持Red Hat, SUSE, Ubuntu。手上没有以上Linux版本,选用了与Red Hat最接近的CentOS7.4来进行安装和测试。

    终于按时完成第二篇。本来准备着手讲一些实践,但是数据库部分没有讲到,部分实践会存在一些问题,于是就有了此篇以及后续——数据库容器化。本篇将从SQL Server容器化实践开始,并逐步讲解其他数据库的容器化实践,中间再穿插一些知识点和实践细节。在编写的过程中,我一直处于一种矛盾的心理,是一笔带过呢?还是尽可能的将实践细节全部讲到位呢?最后,我选择了后者,虽然要花费更多的精力,但是既然开始了本次教程,就尽量写到位吧。

    安装SQL Server on Linux之后,在命令行下使用sqlcmd,你会发现代码提示,语法高亮,甚至连多行复制都不支持,相比之下,MySQL的命令行客户端还好用多了。只做简单的命令管理还行,做数据库开发肯定还得使用SSMS才行。不过,微软不久前发布了一款针对SQL Server新命令行的交互工具——mssql-cli,详细见SQL Server Blog有介绍:

     

     

    新葡亰496net 1

    https://blogs.technet.microsoft.com/dataplatforminsider/2017/12/12/try-mssql-cli-a-new-interactive-command-line-tool-for-sql-server/

    1. 环境

    Linux: CentOS Linux release 7.4.1708 (Core)

    Memory: 4 GB

    SQL Server: SQL Server 2017 (RC2) - 14.0.900.75 (X64)

     

     

    1. 环境

    Linux: CentOS Linux release 7.4.1708 (Core)

    Memory: 4 GB

    SQL Server: SQL Server 2017 (RC2) - 14.0.900.75 (X64)

     

     

    什么是数据库?

    数据库,简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新增、截取、更新、删除等操作。因此,所谓“数据库”是以一定方式储存在一起、能与多个用户共享、具有尽可能小的冗余度、与应用程序彼此独立的数据集合。

    目前主流的数据库分为关系型数据库和非关系型数据库。

     

    2. 安装mssql-server

    2. 安装mssql-server

    关系型数据库和非关系型数据库对比

    新葡亰496net 2

    该工具提供了以下特性:

    2.1 下载rpm包

    [root@134test /opt]# mkdir -p /opt/sqlserver2017
    [root@134test /opt]# cd /opt/sqlserver2017/
    [root@134test /opt]# wget

    2.1 下载rpm包

    [root@134test /opt]# mkdir -p /opt/sqlserver2017
    [root@134test /opt]# cd /opt/sqlserver2017/
    [root@134test /opt]# wget

    主流的数据库

    关系型数据库:

    · Microsoft SQL Server(Microsoft)

    · MySQL

    · Oracle

    · MariaDB(MySQL的代替品)

    · PostgreSQL

    · DB2

    非关系型数据库:

    · MongoDB

    · CouchDB(面向文档,Apache基金会)

    · Redis

    · MemcacheDB

    · Hypertable

    · Hadoop HBase

    随着Docker的流行,主流的数据库厂商均提供了相关的Docker镜像,因此我们能够非常方便的将数据库托管到容器之中,用于测试和开发环境

    注意,现阶段我们不推荐在容器中托管正式环境的数据库,目前数据库容器化还存在一些问题、不适应性以及质疑,并且还缺乏成熟的案例和方案(已经有很多厂商在做这块的探索了,包括阿里、京东)。

    数据库容器化绝不是一个伪命题,数据库容器化是值得我们来探索的一个方向,而且应是一种必然的趋势。在本篇中,我们不做过多探讨。

    新葡亰496net 3

    接下来,笔者将逐步和大家分享如何将主流的数据库托管到容器之中。

    SQL Server是由Microsoft开发和推广的关系数据库,其在操作数据库管理系统 领域处于领先水平,目前已经提供SQL Server 2019预览版。其中,SQL Server 2017 跨出了重要的一步,它力求通过将 SQL Server 的强大功能引入 Linux、基于 Linux 的 Docker 容器和 Windows,使用户可以在 SQL Server 平台上选择开发语言、数据类型、本地开发或云端开发,以及操作系统开发。

    因此,在本篇教程中,我们将使用SQL Server 2017来进行演示。

    新葡亰496net 4

    镜像说明

    官方镜像分为Windows版本和Linux版本,官方镜像说明页为:

    这里我们主要介绍Linux版本的镜像。

    环境要求

    · Docker Engine 1.8 。

    · Dockeroverlay2存储驱动程序。

    · 至少2 GB的磁盘空间。

    · 至少2 GB 的 RAM。如果您在Docker for Mac或Windows上运行,请确保为Docker VM分配足够的内存。

    · Linux 上的 SQL Server 的系统要求。

    环境变量

    必填项:

    · ACCEPT_EULA = Y(表示接受最终用户许可协议,否则无法启动)

    · SA_PASSWORD = <强密码> (密码必须符合复杂密码要求,包含大小写字母以及数字或特殊符号,长度不能少于8个字符,否则无法启动)

    注意项:

    · MSSQL_PID = <your_product_id | edition_name>(用于设置产品ID或版本,默认值:Developer)

    值范围支持Developer、Express、Standard 、Enterprise、EnterpriseCore、产品密钥 ,一般情况下,我们使用Developer即可,即开发版本,其包含企业版所有的功能,足够我们用于开发和测试。

    其他:

    新葡亰496net 5

    • T-SQL IntelliSense T-SQL智能感知
    • Syntax highlighting 语法高亮
    • Pretty formatting for query results, including Vertical Format 查询结果格式美化,包括垂直格式
    • Multi-line edit mode 多行编辑模式
    • Configuration file support 支持配置文件

     

     

    PowerShell运行

    在Windows系统之上,我们可以使用PowerShell来运行SQL Server镜像。脚本如下所示:

    docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=123456abcD" `

    -p 1433:1433 --name mySqlServer `

    -d mcr.microsoft.com/mssql/server:2017-latest

    相关参数说明如下所示:

    新葡亰496net 6新葡亰496net 7

    注意:密码应符合 SQL Server 默认密码策略,否则容器无法设置 SQL Server,将停止工作。 默认情况下,密码必须至少为 8 个字符长,且包含三个以下四种字符集的字符:大写字母、 小写字母、 十进制数字和符号。 你可以通过执行 docker logs 命令检查错误日志。

    执行之后(镜像不存在会自动拉取,大家也可以使用拉取命令下拉取镜像,比如:docker pull mcr.microsoft.com/mssql/server:2017-latest),会默认创建一个使用 SQL Server 2017 开发人员版的容器,端口为1433,密码为123456abcD。

    新葡亰496net 8

    镜像拉取完成之后成功启动:

    新葡亰496net 9

    当然,大家也可以通过命令行查看:

    docker ps -a

    新葡亰496net 10

    如果“状态”列显示“UP”,则 SQL Server 将在容器中运行,并侦听“端口”列中指定的端口。

    新葡亰496net 11

    2.2 yum安装

    [root@134test /opt/sqlserver2017]# yum localinstall mssql-server-14.0.900.75-1.x86_64.rpm

    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Examining mssql-server-14.0.900.75-1.x86_64.rpm: mssql-server-14.0.900.75-1.x86_64
    Marking mssql-server-14.0.900.75-1.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package mssql-server.x86_64 0:14.0.900.75-1 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ===========================================================================================================================================================================
     Package                             Arch                          Version                                

    2.2 yum安装

    [root@134test /opt/sqlserver2017]# yum localinstall mssql-server-14.0.900.75-1.x86_64.rpm

    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Examining mssql-server-14.0.900.75-1.x86_64.rpm: mssql-server-14.0.900.75-1.x86_64
    Marking mssql-server-14.0.900.75-1.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package mssql-server.x86_64 0:14.0.900.75-1 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ===========================================================================================================================================================================
     Package                             Arch                          Version                                

    Bash Shell运行

    如果是Linux系统,我们可以通过Bash Shell执行以下命令:

    sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=123456abcD'

    -p 1433:1433 --name mySqlServer

    -d mcr.microsoft.com/mssql/server:2017-latest

    新葡亰496net 12

    SQL Server Management Studio 是 Microsoft免费提供为开发和管理需求的 SQL 工具套件的一部分。 SSMS 是一个集成的环境,若要访问、 配置、 管理、 管理和开发 SQL Server 的所有组件。 它可以连接到任何平台上运行这两个在本地,在 Docker 容器中和云中的 SQL Server。 它还连接到 Azure SQL 数据库和 Azure SQL 数据仓库。 SSMS 将大量图形工具与丰富的脚本编辑器相结合,各种技术水平的开发人员和管理员都能访问 SQL Server。

    SSMS 提供适用于 SQL Server 的大量开发和管理功能,包括执行以下任务的工具:

    · 配置、 监视和管理单个或多个 SQL Server 实例

    · 部署、 监视和升级数据层组件,如数据库和数据仓库

    · 备份和还原数据库

    · 生成和执行 T-SQL 查询和脚本,并查看结果

    · 生成数据库对象的 T-SQL 脚本

    · 查看和编辑数据库中的数据

    · 以可视方式设计 T-SQL 查询和数据库对象,如视图、 表和存储的过程

    下载地址:

    安装完成之后,我们就可以启动SSMS来进行管理我们的数据库了。

    新葡亰496net 13新葡亰496net 14

    如图所示,我们输入上述内容,以及刚才我们通过环境变量设置的密码“123456abcD”,点击连接,可以看到如下图所示的界面:

    新葡亰496net 15

    我们可以通过界面来管理我们的数据库以及执行相关的查询:

    新葡亰496net 16

    我们可以在容器内部使用 SQL Server 命令行工具 sqlcmd 来连接和管理SQL Server。

    1. 使用 docker exec -it 命令在运行的容器内部启动交互式 Bash Shell

    PowerShell:

    docker exec -it mySqlServer "bash"

    新葡亰496net 17

    bash:

    sudo docker exec -it mySqlServer "bash"

    1. 使用 sqlcmd 进行本地连接。 默认情况下,sqlcmd 不在路径之中,因此需要指定完整路径。

    命令:

    /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '123456abcD'

    新葡亰496net 18

    成功的话,就会显示 sqlcmd 命令提示符 1> 。

    1. 执行SQL脚本。

    比如,我们创建一个MyDb数据库,可以执行以下脚本:

    CREATE DATABASE MyDB

    SELECT Name from sys.Databases

    GO

    第一行为创库脚本,第二行执行查询,查询服务器上所有数据库的名称,第三行为执行。

    注意:只有输入GO才会立即执行之前的命令。

    新葡亰496net 19

    执行结果如上图所示。我们通过SSMS可以查看到我们刚才创建的数据库:

    新葡亰496net 20

    除了以上方式,我们也可以在容器外使用sqlcmd连接数据库:

    sqlcmd -S localhost,1433 -U SA -P "123456abcD"

    新葡亰496net 21

    注意:退出SQLCMD命令为:QUIT。

    除了以上的连接管理工具,大家还可以使用以下工具进行连接:

    · Visual Studio Code

    新葡亰496net 22

    · Azure Data Studio(跨平台数据库工具,适用于在Windows,MacOS和Linux上使用Microsoft系列内部部署和云数据平台的数据专业人员)

    新葡亰496net 23

    · mssql-cli(SQL Server的新的交互式命令行查询工具,支持跨平台,开源,提供智能提示和语法高亮等)

    新葡亰496net 24

    Figure-1:智能提示

    Repository                                                 Size

    Installing:
     mssql-server                        x86_64                        14.0.900.75-1                           /mssql-server-14.0.900.75-1.x86_64                        870 M

    Repository                                                 Size

    Installing:
     mssql-server                        x86_64                        14.0.900.75-1                           /mssql-server-14.0.900.75-1.x86_64                        870 M

     

    Transaction Summary

    Install  1 Package

    Total size: 870 M
    Installed size: 870 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

    --------------------------------------------------------------
    Please run 'sudo /opt/mssql/bin/mssql-conf setup'
    to complete the setup of Microsoft SQL Server
    --------------------------------------------------------------

      Verifying  : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

    Installed:
      mssql-server.x86_64 0:14.0.900.75-1                                                                                                                                      

    Complete!

     

    Transaction Summary

    Install  1 Package

    Total size: 870 M
    Installed size: 870 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

    --------------------------------------------------------------
    Please run 'sudo /opt/mssql/bin/mssql-conf setup'
    to complete the setup of Microsoft SQL Server
    --------------------------------------------------------------

      Verifying  : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

    Installed:
      mssql-server.x86_64 0:14.0.900.75-1                                                                                                                                      

    Complete!

     

    新葡亰496net 25

    2.3 配置

    [root@134test /opt/mssql/bin]# /opt/mssql/bin/mssql-conf setup
    The license terms for this product can be found in
    /usr/share/doc/mssql-server or downloaded from:

    The privacy statement can be viewed at:

    Do you accept the license terms? [Yes/No]:YES

    Choose an edition of SQL Server:
      1) Evaluation (free, no production use rights, 180-day limit)
      2) Developer (free, no production use rights)
      3) Express (free)
      4) Web (PAID)
      5) Standard (PAID)
      6) Enterprise (PAID)
      7) I bought a license through a retail sales channel and have a product key to enter.

    Details about editions can be found at

    Use of PAID editions of this software requires separate licensing through a
    Microsoft Volume Licensing program.
    By choosing a PAID edition, you are verifying that you have the appropriate
    number of licenses in place to install and run this software.

    Enter your edition(1-7): 2
    Enter the SQL Server system administrator password:
    Confirm the SQL Server system administrator password:
    Configuring SQL Server...

    This is an evaluation version.  There are [40] days left in the evaluation period.
    Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
    Setup has completed successfully. SQL Server is now starting.

     

    注意评估版本有使用期限。

     

    2.3 配置

    [root@134test /opt/mssql/bin]# /opt/mssql/bin/mssql-conf setup
    The license terms for this product can be found in
    /usr/share/doc/mssql-server or downloaded from:

    The privacy statement can be viewed at:

    Do you accept the license terms? [Yes/No]:YES

    Choose an edition of SQL Server:
      1) Evaluation (free, no production use rights, 180-day limit)
      2) Developer (free, no production use rights)
      3) Express (free)
      4) Web (PAID)
      5) Standard (PAID)
      6) Enterprise (PAID)
      7) I bought a license through a retail sales channel and have a product key to enter.

    Details about editions can be found at

    Use of PAID editions of this software requires separate licensing through a
    Microsoft Volume Licensing program.
    By choosing a PAID edition, you are verifying that you have the appropriate
    number of licenses in place to install and run this software.

    Enter your edition(1-7): 2
    Enter the SQL Server system administrator password:
    Confirm the SQL Server system administrator password:
    Configuring SQL Server...

    This is an evaluation version.  There are [40] days left in the evaluation period.
    Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
    Setup has completed successfully. SQL Server is now starting.

     

    注意评估版本有使用期限。

     

    Figure-2:格式化显示

    2.4 验证服务

    [root@134test /opt/mssql/bin]# systemctl status mssql-server
    ● mssql-server.service - Microsoft SQL Server Database Engine
       Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
       Active: active (running)since Thu 2017-12-14 18:25:03 CST; 1min 23s ago
         Docs:
     Main PID: 56504 (sqlservr)
       CGroup: /system.slice/mssql-server.service
               ├─56504 /opt/mssql/bin/sqlservr
               └─56525 /opt/mssql/bin/sqlservr

    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.36 Server      Server is listening on [ ::1 <ipv6> 1434].
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Dedicated admin connection support was established for listening locally on port 1434.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.38 spid19s     SQL Server is now ready for client connections. This is an informational message; ... required.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.42 spid9s      Starting up database 'tempdb'.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid9s      The tempdb database has 1 data file(s).
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid20s     The Service Broker endpoint is in disabled or stopped state.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     Service Broker manager has started.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.63 spid6s      Recovery is complete. This is an informational message only. No user action is required.
    Hint: Some lines were ellipsized, use -l to show in full.

    2.5 停止、启动或重启 SQL Server 服务
    systemctl stop mssql-server
    systemctl start mssql-server
    systemctl restart mssql-server

    2.6 日志文件
    /var/opt/mssql/log/errorlog

    2.4 验证服务

    [root@134test /opt/mssql/bin]# systemctl status mssql-server
    ● mssql-server.service - Microsoft SQL Server Database Engine
       Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
       Active: active (running)since Thu 2017-12-14 18:25:03 CST; 1min 23s ago
         Docs:
     Main PID: 56504 (sqlservr)
       CGroup: /system.slice/mssql-server.service
               ├─56504 /opt/mssql/bin/sqlservr
               └─56525 /opt/mssql/bin/sqlservr

    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.36 Server      Server is listening on [ ::1 <ipv6> 1434].
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Dedicated admin connection support was established for listening locally on port 1434.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.38 spid19s     SQL Server is now ready for client connections. This is an informational message; ... required.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.42 spid9s      Starting up database 'tempdb'.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid9s      The tempdb database has 1 data file(s).
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid20s     The Service Broker endpoint is in disabled or stopped state.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     Service Broker manager has started.
    Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.63 spid6s      Recovery is complete. This is an informational message only. No user action is required.
    Hint: Some lines were ellipsized, use -l to show in full.

    2.5 停止、启动或重启 SQL Server 服务
    systemctl stop mssql-server
    systemctl start mssql-server
    systemctl restart mssql-server

    2.6 日志文件
    /var/opt/mssql/log/errorlog

     

    3. 安装 sqlcmd 和 bcp SQL Server 命令行工具

    3. 安装 sqlcmd 和 bcp SQL Server 命令行工具

     

    3.1 下载

    wget
    wget

    3.1 下载

    wget
    wget

    1. 安装

    3.2 安装

    yum localinstall msodbcsql-13.1.6.0-1.x86_64.rpm
    yum localinstall mssql-tools-14.0.5.0-1.x86_64.rpm

    3.2 安装

    yum localinstall msodbcsql-13.1.6.0-1.x86_64.rpm
    yum localinstall mssql-tools-14.0.5.0-1.x86_64.rpm

    下面就来试用下这款工具吧。这里仅以CentOS7下演示,其他平台可参考SQL Server Blog,或者在Github上有更详细的安装指引:https://github.com/dbcli/mssql-cli/blob/master/doc/installation_guide.md

    3.3 添加到环境变量

    [root@134test /opt]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
    [root@134test /opt]# source ~/.bash_profile
    [root@134test /opt]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    [root@134test /opt]# source ~/.bashrc

    3.3 添加到环境变量

    [root@134test /opt]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
    [root@134test /opt]# source ~/.bash_profile
    [root@134test /opt]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    [root@134test /opt]# source ~/.bashrc

     

    3.4 本地连接

    [root@134test /opt/mssql/bin]# sqlcmd -S localhost -U sa
    Password:
    1> select name from sys.databases;
    2> go
    新葡亰496net数据水库蓄水容量器化,CentOS7脱机安装SQL。name                                                                                                                          

    3.4 本地连接

    [root@134test /opt/mssql/bin]# sqlcmd -S localhost -U sa
    Password:
    1> select name from sys.databases;
    2> go
    name                                                                                                                          

     

     

    master                                                                                                                          
    tempdb                                                                                                                          
    model                                                                                                                           
    msdb                                                                                                                                                                                                                                           

    (5 rows affected)
    1>
    1>create database TestDB;
    2>go
    1>

    1> use TestDB;
    2> go
    Changed database context to 'TestDB'.
    1> create table t1 (id int, cname nvarchar(50))
    2> go
    1>
    1> insert into t1 (id, cname) values (1,'abc');
    2> go

    (1 rows affected)
    1> select * from t1;
    2> go
    id          cname                                             


              1 abc                                               

    (1 rows affected)
    1>

     

    master                                                                                                                          
    tempdb                                                                                                                          
    model                                                                                                                           
    msdb                                                                                                                                                                                                                                           

    (5 rows affected)
    1>
    1>create database TestDB;
    2>go
    1>

    1> use TestDB;
    2> go
    Changed database context to 'TestDB'.
    1> create table t1 (id int, cname nvarchar(50))
    2> go
    1>
    1> insert into t1 (id, cname) values (1,'abc');
    2> go

    新葡亰496net,(1 rows affected)
    1> select * from t1;
    2> go
    id          cname                                             


              1 abc                                               

    (1 rows affected)
    1>

    2.1 安装最新的EPEL(Extra Packages for Enterprise Linux)

    3.5 退出

    1> quit

    3.5 退出

    1> quit

    [root@134test ~]# yum install epel-release

    4. 安装SQL Server Agent

    4. 安装SQL Server Agent

     

    4.1 下载

    wget

    4.1 下载

    wget

    2.2 安装相关依赖

     

     

    [root@134test ~]# yum install libunwind libicu python-pip

    4.2 安装

    [root@134test /opt/sqlserver2017]# yum localinstall mssql-server-agent-14.0.900.75-1.x86_64.rpm
    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Examining mssql-server-agent-14.0.900.75-1.x86_64.rpm: mssql-server-agent-14.0.900.75-1.x86_64
    Marking mssql-server-agent-14.0.900.75-1.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package mssql-server-agent.x86_64 0:14.0.900.75-1 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ===========================================================================================================================================================================
     Package                                Arch                       Version                             

    4.2 安装

    [root@134test /opt/sqlserver2017]# yum localinstall mssql-server-agent-14.0.900.75-1.x86_64.rpm
    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Examining mssql-server-agent-14.0.900.75-1.x86_64.rpm: mssql-server-agent-14.0.900.75-1.x86_64
    Marking mssql-server-agent-14.0.900.75-1.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package mssql-server-agent.x86_64 0:14.0.900.75-1 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ===========================================================================================================================================================================
     Package                                Arch                       Version                             

     

    Repository                                                    Size

    Installing:
     mssql-server-agent                     x86_64                     14.0.900.75-1                        /mssql-server-agent-14.0.900.75-1.x86_64                     8.9 M

    Repository                                                    Size

    Installing:
     mssql-server-agent                     x86_64                     14.0.900.75-1                        /mssql-server-agent-14.0.900.75-1.x86_64                     8.9 M

    2.3 安装mssql-cli

    Transaction Summary

    Install  1 Package

    Total size: 8.9 M
    Installed size: 8.9 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

    --------------------------------------------------------------------------------
    Please restart mssql-server to enable Microsoft SQL Server Agent.
    --------------------------------------------------------------------------------

      Verifying  : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

    Installed:
      mssql-server-agent.x86_64 0:14.0.900.75-1                                                                                                                                

    Complete!

    Transaction Summary

    Install  1 Package

    Total size: 8.9 M
    Installed size: 8.9 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

    --------------------------------------------------------------------------------
    Please restart mssql-server to enable Microsoft SQL Server Agent.
    --------------------------------------------------------------------------------

      Verifying  : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

    Installed:
      mssql-server-agent.x86_64 0:14.0.900.75-1                                                                                                                                

    Complete!

    [root@134test ~]# pip install mssql-cli

    5. 在Windows上使用SSMS连接数据库

    新葡亰496net 26

    Figure-1:SSMS连接Linux下的数据库

     

    新葡亰496net 27

    Figure-2:查询版本信息

     

    SELECT @@VERSION;
    GO
    Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)
        Jul 27 2017 08:53:49
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (CentOS Linux 7 (Core))
    

    新葡亰496net 28
    Figure-3:查询数据

    发现Red Gate部分功能不能使用。rpm包安装无法指定安装目录。

     

    5. 在Windows上使用SSMS连接数据库

    新葡亰496net 29

    Figure-1:SSMS连接Linux下的数据库

     

    新葡亰496net 30

    Figure-2:查询版本信息

     

    SELECT @@VERSION;
    GO
    Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)
        Jul 27 2017 08:53:49
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (CentOS Linux 7 (Core))
    

    新葡亰496net 31
    Figure-3:查询数据

    发现Red Gate部分功能不能使用。rpm包安装无法指定安装目录。

     

     

    6. 参考




     

     

     

     

    6. 参考




     

     

     

     

    2.4 使用mssql-cli登录

    [root@134test ~]# mssql-cli -U sa

    Password:

    Version: 0.8.0

    Mail: sqlcli@microsoft.com

    Home:

    master>SELECT @@version

    --------------------

    | (No column name) |

    |--------------------|

    | Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)

    Jul 27 2017 08:53:49

    Copyright (C) 2017 Microsoft Corporation

    Developer Edition (64-bit) on Linux (CentOS Linux 7 (Core)) |

    --------------------

    (1 row affected)

    Time: 0.103s

    master>

     

     

     

    1. 体验

    在Xshell使用mssql-cli,有以下几点心得,欢迎补充。

    • 语法高亮,智能提示,查询结果格式美化都有了。
    • 如果横向显示的字段过长,会自动把表的字段以纵向的格式显示,并支持逐行上下翻。
    • 直接回车即可执行语句,无须以GO结束。

     

    不过也发现几个问题:

    • 直接粘贴多行语句还是会出错。(难道我复制的姿势不对?)
    • 查询返回的数据较多,返回结果较慢;查询较大的数据,很慢。若是等不及按下两次ctrl c,会如下错误。
    • 字段的内容过长无法显示完整。

    新葡亰496net 32

    Figure-3:查询过程中两次ctrl c后报错

     

    新葡亰496net 33

    Figure-3:字段的内容显示不完整

     

     

    1. 总结

    在命令行环境下有所增强的功能还是挺好的,适合于没有图形化界面的场景下使用。如果用于开发、管理或查询等,有条件的情况下,还是建议在Windows平台下使用SSMS吧。

     

    另外再补充一下:http://www.codeplex.com/已经不再更新,要下载SQL Server的示例数据库直接到Github(https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks)下载更方便。

     

     

    本文由新葡亰496net发布于网络数据库,转载请注明出处:新葡亰496net数据水库蓄水容量器化,CentOS7脱机安

    关键词: