先日、Microsoft SQL Server 2017をCentOS 7にインストールしました。
今回はコマンドライン・ツールをインストールします。
Install SQL Server and create a database on Red Hat
https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat
環境
・CentOS Linux release 7.4.1708 (Core)
・Kernel 3.10.0-693.2.2.el7.x86_64
- repositoryのダウンロード
- mssql-tools,unixODBC-develのインストール
- 接続
1 2 3 4 5 6 7 8 9 10 11 12 |
# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 193 100 193 0 0 193 0 0:00:01 --:--:-- 0:00:01 442 # cat /etc/yum.repos.d/msprod.repo [packages-microsoft-com-prod] name=packages-microsoft-com-prod baseurl=https://packages.microsoft.com/rhel/7/prod/ enabled=1 gpgcheck=1 gpgkey=https://packages.microsoft.com/keys/microsoft.asc |
インストールの途中でライセンス許諾を求められます。
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# repoquery --list mssql-tools /opt/mssql-tools/bin /opt/mssql-tools/bin/bcp /opt/mssql-tools/bin/sqlcmd /opt/mssql-tools/share /opt/mssql-tools/share/resources /opt/mssql-tools/share/resources/en_US /opt/mssql-tools/share/resources/en_US/BatchParserGrammar.dfa /opt/mssql-tools/share/resources/en_US/BatchParserGrammar.llr /opt/mssql-tools/share/resources/en_US/SQLCMD.rll /opt/mssql-tools/share/resources/en_US/bcp.rll /usr/share/doc/mssql-tools /usr/share/doc/mssql-tools/LICENSE.txt /usr/share/doc/mssql-tools/THIRDPARTYNOTICES.txt # repoquery --list unixODBC-devel /usr/include/autotest.h /usr/include/odbcinst.h /usr/include/odbcinstext.h /usr/include/sql.h /usr/include/sqlext.h /usr/include/sqltypes.h /usr/include/sqlucode.h /usr/include/unixodbc_conf.h /usr/include/unixodbc_conf_i386.h /usr/include/uodbc_extras.h /usr/include/uodbc_stats.h /usr/lib/libesoobS.so /usr/lib/libmimerS.so /usr/lib/libnn.so /usr/lib/libodbccr.so /usr/lib/libodbcdrvcfg1S.so /usr/lib/libodbcdrvcfg2S.so /usr/lib/libodbcminiS.so /usr/lib/libodbcnnS.so /usr/lib/libodbctxtS.so /usr/lib/liboplodbcS.so /usr/lib/liboraodbcS.so /usr/lib/libsapdbS.so /usr/lib/libtdsS.so /usr/lib/libtemplate.so /usr/include/autotest.h /usr/include/odbcinst.h /usr/include/odbcinstext.h /usr/include/sql.h /usr/include/sqlext.h /usr/include/sqltypes.h /usr/include/sqlucode.h /usr/include/unixodbc_conf.h /usr/include/unixodbc_conf_x86_64.h /usr/include/uodbc_extras.h /usr/include/uodbc_stats.h /usr/lib64/libesoobS.so /usr/lib64/libmimerS.so /usr/lib64/libnn.so /usr/lib64/libodbccr.so /usr/lib64/libodbcdrvcfg1S.so /usr/lib64/libodbcdrvcfg2S.so /usr/lib64/libodbcminiS.so /usr/lib64/libodbcnnS.so /usr/lib64/libodbctxtS.so /usr/lib64/liboplodbcS.so /usr/lib64/liboraodbcS.so /usr/lib64/libsapdbS.so /usr/lib64/libtdsS.so /usr/lib64/libtemplate.so # yum install -y mssql-tools unixODBC-devel Resolving Dependencies --> Running transaction check ---> Package mssql-tools.x86_64 0:14.0.6.0-1 will be installed --> Processing Dependency: msodbcsql < 13.2.0.0 for package: mssql-tools-14.0.6.0-1.x86_64 --> Processing Dependency: msodbcsql >= 13.1.0.0 for package: mssql-tools-14.0.6.0-1.x86_64 ---> Package unixODBC-devel.x86_64 0:2.3.1-11.el7 will be installed --> Processing Dependency: unixODBC(x86-64) = 2.3.1-11.el7 for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libtemplate.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libtdsS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libsapdbS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: liboraodbcS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: liboplodbcS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbctxtS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcnnS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcminiS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcdrvcfg2S.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcdrvcfg1S.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbccr.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libnn.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libmimerS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libesoobS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Running transaction check ---> Package msodbcsql.x86_64 0:13.1.9.1-1 will be installed ---> Package unixODBC.x86_64 0:2.3.1-11.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================================== Package Arch Version Repository Size =========================================================================================================================== Installing: mssql-tools x86_64 14.0.6.0-1 packages-microsoft-com-prod 249 k unixODBC-devel x86_64 2.3.1-11.el7 base 55 k Installing for dependencies: msodbcsql x86_64 13.1.9.1-1 packages-microsoft-com-prod 4.0 M unixODBC x86_64 2.3.1-11.el7 base 413 k Transaction Summary =========================================================================================================================== Install 2 Packages (+2 Dependent packages) Total download size: 4.7 M Installed size: 5.6 M Downloading packages: (1/4): unixODBC-devel-2.3.1-11.el7.x86_64.rpm | 55 kB 00:00:00 (2/4): unixODBC-2.3.1-11.el7.x86_64.rpm | 413 kB 00:00:00 (3/4): mssql-tools-14.0.6.0-1.x86_64.rpm | 249 kB 00:00:00 (4/4): msodbcsql-13.1.9.1-1.x86_64.rpm | 4.0 MB 00:00:03 --------------------------------------------------------------------------------------------------------------------------- Total 1.4 MB/s | 4.7 MB 00:00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : unixODBC-2.3.1-11.el7.x86_64 1 The license terms for this product can be downloaded from https://aka.ms/odbc131eula and found in /usr/share/doc/msodbcsql/LICENSE.TXT . By entering 'YES', you indicate that you accept the license terms. Do you accept the license terms? (Enter YES or NO) YES Installing : msodbcsql-13.1.9.1-1.x86_64 2 The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746949 and found in /usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES', you indicate that you accept the license terms. Do you accept the license terms? (Enter YES or NO) YES Installing : mssql-tools-14.0.6.0-1.x86_64 3 Installing : unixODBC-devel-2.3.1-11.el7.x86_64 4 Verifying : msodbcsql-13.1.9.1-1.x86_64 1 Verifying : unixODBC-devel-2.3.1-11.el7.x86_64 2 Verifying : unixODBC-2.3.1-11.el7.x86_64 3 Verifying : mssql-tools-14.0.6.0-1.x86_64 4 Installed: mssql-tools.x86_64 0:14.0.6.0-1 unixODBC-devel.x86_64 0:2.3.1-11.el7 Dependency Installed: msodbcsql.x86_64 0:13.1.9.1-1 unixODBC.x86_64 0:2.3.1-11.el7 Complete! |
コマンドは/opt/mssql-tools/bin/にインストールされます。
PATHを設定した方が楽ですが、取り敢えず動作確認してみます。
パスワードは/opt/mssql/bin/mssql-conf setupで設定したパスワードを指定します。
1 2 3 4 5 6 7 8 9 10 11 12 |
# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SA-Password' 1> SELECT Name from sys.Databases 2> go Name -------------------------------------------------------------------------------------------------------------------------------- master tempdb model msdb (4 rows affected) 1> quit |
パスワードを省略したら入力を求められます。
1 2 3 |
# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA Password: 1> quit |
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 |
# /opt/mssql-tools/bin/sqlcmd Microsoft (R) SQL Server Command Line Tool Version 13.1.0007.0 Linux Copyright (c) 2012 Microsoft. All rights reserved. usage: sqlcmd [-U login id] [-P password] [-S server or Dsn if -D is provided] [-H hostname] [-E trusted connection] [-N Encrypt Connection][-C Trust Server Certificate] [-d use database name] [-l login timeout] [-t query timeout] [-h headers] [-s colseparator] [-w screen width] [-a packetsize] [-e echo input] [-I Enable Quoted Identifiers] [-c cmdend] [-q "cmdline query"] [-Q "cmdline query" and exit] [-m errorlevel] [-V severitylevel] [-W remove trailing spaces] [-u unicode output] [-r[0|1] msgs to stderr] [-i inputfile] [-o outputfile] [-k[1|2] remove[replace] control characters] [-y variable length type display width] [-Y fixed length type display width] [-p[1] print statistics[colon format]] [-R use client regional setting] [-K application intent] [-M multisubnet failover] [-b On error batch abort] [-D Dsn flag, indicate -S is Dsn] [-X[1] disable commands, startup script, environment variables [and exit]] [-x disable variable substitution] [-? show syntax summary] |