如何从 Mac OS X 终端使用 MS SQL Server?

发布于 2024-10-26 03:26:58 字数 641 浏览 1 评论 0原文

我使用 Mac 开发网络应用程序。我们的运行时是 Java,我们的 Web 服务器是 Jetty,我们的 IDE 是 Eclipse。因此,我们的整个堆栈可以在 Mac 和 Windows 上本地使用……除了我们的数据库,即 MS SQL Server(范围从 2000 年到 2008 年,具体取决于应用程序)。我想要一个适用于 MS SQL Server 的 Unix 命令行客户端。

我不喜欢任何 SQL Server 的 OS X GUI 客户端 – 我发现它们很乏味,而且不太像 Mac – 所以目前我通过 VMWare Fusion 在 Windows XP 上使用 SQL Server 2008 Management Studio。但启动和退出仍然是一个巨大的痛苦,它在运行时会耗尽我的 RAM,并且每次使用它时都会更改磁盘上的几个 2GB 文件,从而毒害我的时间机器备份。

我喜欢从命令行使用 MySQL,因此这似乎是快速访问数据库并调查错误或添加一些测试数据的好方法。如果我能那样使用 SQL Server 就好了!如果我自己无法直接使用 JDBC 实现命令行客户端,有什么办法可以实现这一点吗?

I use a Mac to develop web apps. Our runtime is Java, our web server is Jetty, and our IDE is Eclipse. So our whole stack can be used from Mac and Windows natively … with the exception of our database, which is MS SQL Server (ranging from 2000 to 2008 depending on the application). I want a Unix command-line client for MS SQL Server.

I don't like any of the OS X GUI clients for SQL Server – I find them tedious and not very Mac-like – so for the time being I use SQL Server 2008 Management Studio, on Windows XP, via VMWare Fusion. But it's still a huge pain to launch and quit, it eats up my RAM while it's running, and it poisons my Time Machine backups by altering several 2GB files on disk every time I use it.

I like how MySQL can be used from the command line, so that seems like a great way to quickly get to my database and investigate a bug or add some test data. If only I could use SQL Server that way! Short of implementing a command line client myself using straight JDBC, there anything out there that makes this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

回眸一笑 2024-11-02 03:26:58

这个开源节点应用程序于 2014 年推出,sql-cli,为 Mac OS X 和其他桌面提供有用的命令行控制台。

This open source node app that came out in 2014, sql-cli, provides a useful command line console for Mac OS X and other desktops.

中二柚 2024-11-02 03:26:58

Microsoft 现在为 SQL Server 提供命令行工具的 OS X 二进制文件,包括 sqlcmd 以及第一方 ODBC 驱动程序。从理论上讲,如果 Mac 相应配置了 Kerberos,那么这应该支持与 Windows 身份验证连接 - 这是 sql-cli 工具不太可能提供的功能。

它们作为 Homebrew 软件包分发:

$ brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
$ brew update
$ ACCEPT_EULA=y brew install --no-sandbox msodbcsql mssql-tools

将 OS X 主机作为客户端连接到 SQL Server 运行在 Docker 中:

$ sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
1> SELECT @@VERSION AS 'SQL Server Version'
2> GO
SELECT @@VERSION AS 'SQL Server Version'

SQL Server Version
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
    Aug 22 2017 17:04:49
    Copyright (C) 2017 Microsoft Corporation
    Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

(1 rows affected)
1> quit

您可以在 ~/.odbc.ini 中配置 DSN:

# Give -D to connect using a DSN:
# sqlcmd -S DockerMS -D -U user -P password

[DockerMS]
Driver = ODBC Driver 13 for SQL Server
Server = 127.0.0.1,1433
Database = YourDefaultDB

其中 Driver 设置与安装过程中向 unixODBC 注册的名称相匹配,请参阅<代码>odbcinst -q -d。

Microsoft now provides OS X binaries of Command Line Tools for SQL Server, including sqlcmd, along with a first-party ODBC driver. This should, in theory, support connecting with Windows Authentication if the Mac has Kerberos configured accordingly—something the sql-cli tool doesn't likely offer.

These are distributed as Homebrew packages:

$ brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
$ brew update
$ ACCEPT_EULA=y brew install --no-sandbox msodbcsql mssql-tools

Connecting OS X host as a client to SQL Server running in Docker:

$ sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
1> SELECT @@VERSION AS 'SQL Server Version'
2> GO
SELECT @@VERSION AS 'SQL Server Version'

SQL Server Version
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
    Aug 22 2017 17:04:49
    Copyright (C) 2017 Microsoft Corporation
    Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

(1 rows affected)
1> quit

You can configure DSNs in ~/.odbc.ini:

# Give -D to connect using a DSN:
# sqlcmd -S DockerMS -D -U user -P password

[DockerMS]
Driver = ODBC Driver 13 for SQL Server
Server = 127.0.0.1,1433
Database = YourDefaultDB

where the Driver setting matches the name registered with unixODBC by the installation process, see odbcinst -q -d.

当爱已成负担 2024-11-02 03:26:58

安装 FreeTDS 然后就可以运行 sqsh 从终端输入

Install FreeTDS and then you can run sqsh form the terminal

枕花眠 2024-11-02 03:26:58

尽管我更喜欢在 Mac 上使用 Azure Data Studio,但我曾经在命令行上使用 MS SQL 工作过一段时间。我使用跨平台工具 sql-cli 完成了此操作。

假设你已经安装了 npm,
在终端上运行以下命令 -

    npm install -g sql-cli

如果出现权限错误,请尝试以 root/管理员身份运行此命令,但这次要在前面添加 sudo 命令。

    sudo npm install -g sql-cli

现在连接到 MS SQL 服务器

    mssql -u sa -p myPassw0rd

您应该会看到这样的结果:

    Connecting to localhost...done

      sql-cli version 0.6.2
      Enter ".help" for usage hints.
      mssql>

要检查您的 SQL Server 是否正在运行,请输入以下命令运行测试:

    select @@version

如果您的服务器正在运行,您应该会看到类似于以下内容的输出:

    Microsoft SQL Server 2019 (RTM-CU4) (KB4056498) - 15.0.2022.28 (X64) 
        May 9 2020 10:39:09 
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

    1 row(s) returned

    Executed in 1 ms
    mssql>

Even though I prefer using Azure Data Studio on the Mac, I used to work on the command line with MS SQL for a little while. I did this using the cross-platform tool sql-cli.

Assuming you have installed npm,
run the below command on the terminal -

    npm install -g sql-cli

if you have a permission error, try running this as root/Administrator, but this time by prepending the sudo command.

    sudo npm install -g sql-cli

Now connect to the MS SQL server

    mssql -u sa -p myPassw0rd

You should expect something of this sort:

    Connecting to localhost...done

      sql-cli version 0.6.2
      Enter ".help" for usage hints.
      mssql>

To check is your SQL Server is running run a test by typing in the command:

    select @@version

If your server is running, you should see an output similar to this:

    Microsoft SQL Server 2019 (RTM-CU4) (KB4056498) - 15.0.2022.28 (X64) 
        May 9 2020 10:39:09 
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

    1 row(s) returned

    Executed in 1 ms
    mssql>
つ可否回来 2024-11-02 03:26:58

免费、开源、基于 Java:SQuirreL

您可能不会像使用 MySQL 或 Oracle 那样获得基于命令行的 SQL Server 工具。几乎您需要执行的每个命令和操作都是 SQL 命令:您只需要一个 SQL 客户端

Free, open source, Java based: SQuirreL?

You probably won't get a command line based tool for SQL Server in the same way you'd do stuff for MySQL or Oracle. Almost every command and action that you need to do are SQL commands: you just need a SQL client

脱离于你 2024-11-02 03:26:58

尝试使用 Azure Data Studio,跨平台工具。我在 MAC 上用作 SQL 客户端,认为它是最好的。
与其他免费 SQL 客户端不同,它是免费且用户友好的。

Try using the Azure Data Studio, cross-platform tool. I am using as a SQL client On MAC and fell it is the best.
It is free and User-friendly, unlike other Free SQL clients.

提赋 2024-11-02 03:26:58

$ pip install mssql-cli

您可以在 https://learn.microsoft.com/pt-br/sql/tools/mssql-cli?view=sql-server-ver15 了解更多信息。

$ pip install mssql-cli

You can find more info in https://learn.microsoft.com/pt-br/sql/tools/mssql-cli?view=sql-server-ver15 for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文